Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When use with Django Components, changes to the .py files do not update until server restart #224

Open
ayoung-burnsmcd opened this issue Nov 13, 2023 · 6 comments · May be fixed by #229
Open

Comments

@ayoung-burnsmcd
Copy link

Python Version

3.9.18

Django Version

4.2.7

Package Version

No response

Browser

No response

Description

When used with Django Components you have to restart the server every time you update the .py file that registers the component.

If you disable Django Browser Reload then the component functionality works as expected.

I created a sample repo with a project demonstrating the issue. Directions are in the project readme.

https://github.com/ayoung-burnsmcd/components-browser-reload

@adamchainz
Copy link
Owner

Are you saying that without Django-browser-reload, the server does restart? And that with Django-browser-reload, it does?

@ayoung-burnsmcd
Copy link
Author

Without Django-browser-reload, runserver recognizes the update to the Django-component .py file and will output the updates on a browser refresh.

With Django-browser-reload, runserver does not recognizes the update to the Django-component .py file and will not show the update until the server is stopped and restarted.

@imankulov
Copy link

We encountered the same issue.

django-components stores Python files along with their media files and HTML templates. It uses django_components.template_loader.Loader, which extends the template directory list to include the parent directories of the Python components.

Ref: https://github.com/EmilStenstrom/django-components#installation

The "django-browser-reload" app prevents the server from being reloaded when there are changes in the component Python files, as it considers them either template files or static assets.

Ref: https://github.com/adamchainz/django-browser-reload/blob/main/src/django_browser_reload/views.py#L114

If we agree that Python files are specific enough to require server-side reloading, regardless of their location, the fix should be quite straightforward. I am ready to create a pull request.

As a further development of this idea, we can configure the list of extensions that always require a reload via settings. However, I am not sure what else, besides Python, should be included there.

@ayoung-burnsmcd
Copy link
Author

ayoung-burnsmcd commented Dec 5, 2023

A list of extensions, or extensions at a path, would be a great solution. This would allow current functionality to be unaltered while allowing a developer to customize as needed.

imankulov added a commit to imankulov/django-browser-reload that referenced this issue Dec 6, 2023
Force server reload when Python files are changed even if they are in
templates or static directories.

Fixes adamchainz#224
@imankulov
Copy link

I've created a PR #229 to address the issue, and I took the liberty of hardcoding the Python extension as the one that forces the development server to reload regardless.

I decided not to parameterize it because I felt like it was such a rare case that adding a settings option for it and documenting it would be more confusing than helpful. It would be a separate but puzzling challenge -- how would we name that settings option if we decided to introduce it? 🤷

However, I am open to feedback. I would especially love to hear @adamchainz's input. Thank you!

@ayoung-burnsmcd
Copy link
Author

I applied the patch in #229 locally and it worked great!

Thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants