Skip to content

feat: hot-reload component files without server restart - #1657

Merged
JuroOravec merged 6 commits into
masterfrom
jo-feat-hot-reload
Jun 3, 2026
Merged

JuroOravec merged 6 commits into
masterfrom
jo-feat-hot-reload

Conversation

@JuroOravec

@JuroOravec JuroOravec commented Jun 3, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • When a component's template_file, js_file, or css_file changes on disk, the dev server now picks up the change on the next request without restarting. This matches how standard Django templates already work.
  • Changes the reload_on_file_change setting from bool to support "off" | "hot" | "restart" (plus bool for backward compat). Default is now "hot" (was False).
  • "restart" mode is deprecated and marked TODO_REMOVE_IN_V1.

How it works

  1. A file-to-component reverse index (_component_file_cache) maps absolute file paths to component classes (weakrefs).
  2. On Django's file_changed signal, we look up affected components and clear their ComponentMedia cache + the dependency rendering cache.
  3. The handler returns True to suppress Django's server restart (in "hot" mode).
  4. Next request triggers lazy re-read from disk via _load_media().

Files changed

  • app_settings.py - ReloadMode enum, updated setting type/default/normalizer
  • component_media.py - reverse index, reset_template(), reset_files()
  • dependencies.py - evict_component_scripts() to clear the dependency rendering cache
  • apps.py - _setup_component_file_reload() signal handler
  • __init__.py - export ReloadMode, ReloadModeType
  • util/testing.py - test cleanup for the new cache
  • tests/test_hotreload.py - 24 tests covering all scenarios

Closes #1324
Closes #1461

Test plan

  • 24 new tests in test_hotreload.py (template/JS/CSS reload, multiple components sharing a file, signal suppression in hot mode, restart mode, off mode, weakref cleanup)
  • Manually verified with sampleproject: edit CSS, refresh browser, see updated styles without server restart
  • Existing test suite passes (pytest, ruff, mypy)

🤖 Generated with Claude Code

JuroOravec and others added 2 commits June 3, 2026 15:31
When a component's template, JS, or CSS file changes on disk, the
dev server now picks up the change on the next request without
restarting. This matches how standard Django templates already work.

Changes the `reload_on_file_change` setting from `bool` to support
`"off"` | `"hot"` | `"restart"` (plus bool for backward compat).
Default is now `"hot"` (was `False`).

Closes #1324

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
- Replace autoref-style [text][Key] links with relative markdown links
  in development_server.md (master uses this format, not autorefs)
- Fix stale anchor #reload-dev-server-on-component-file-changes to
  match renamed heading #hot-reloading-component-files-during-development
- Add ReloadMode entry to docs/reference/api.md (gen script is broken)

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Performance Benchmark Results

Comparing PR changes against master branch:

Benchmarks that have stayed the same:

Change Before [6b9d3fd] After [19e9b37] Ratio Benchmark (Parameter)
63.2±2ms 62.4±1ms 0.99 Components vs Django.timeraw_render_lg_first('django')
234±4ms 231±4ms 0.99 Components vs Django.timeraw_render_lg_first('django-components')

@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Performance Benchmark Results

Comparing PR changes against master branch:

Benchmarks that have stayed the same:

Change Before [6b9d3fd] After [82a4912] Ratio Benchmark (Parameter)
64.0±2ms 63.2±0.9ms 0.99 Components vs Django.timeraw_render_lg_first('django')
229±3ms 232±6ms 1.01 Components vs Django.timeraw_render_lg_first('django-components')

@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Performance Benchmark Results

Comparing PR changes against master branch:

Benchmarks that have stayed the same:

Change Before [6b9d3fd] After [28939ac] Ratio Benchmark (Parameter)
69.6±2ms 70.3±1ms 1.01 Components vs Django.timeraw_render_lg_first('django')
251±3ms 251±4ms 1 Components vs Django.timeraw_render_lg_first('django-components')

JuroOravec and others added 2 commits June 3, 2026 16:04
Tests used fake Unix paths like "/some/tracked/template.html" which
Path.resolve() transforms differently on Windows (prepends drive letter).
Use real temp files instead so paths resolve consistently cross-platform.

Also suppress pre-existing mypy call-arg error on pydantic BaseSettings
(reads required fields from env vars, which mypy can't verify).

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Performance Benchmark Results

Comparing PR changes against master branch:

Benchmarks that have stayed the same:

Change Before [6b9d3fd] After [6270284] Ratio Benchmark (Parameter)
69.0±0.3ms 69.0±0.3ms 1 Components vs Django.timeraw_render_lg_first('django')
244±3ms 243±2ms 1 Components vs Django.timeraw_render_lg_first('django-components')

@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Performance Benchmark Results

Comparing PR changes against master branch:

Benchmarks that have stayed the same:

Change Before [6b9d3fd] After [3ebee5f] Ratio Benchmark (Parameter)
68.6±0.3ms 69.2±1ms 1.01 Components vs Django.timeraw_render_lg_first('django')
242±3ms 243±5ms 1 Components vs Django.timeraw_render_lg_first('django-components')

@JuroOravec
JuroOravec merged commit 854cd62 into master Jun 3, 2026
15 checks passed
@JuroOravec
JuroOravec deleted the jo-feat-hot-reload branch June 3, 2026 14:36
@JuroOravec JuroOravec mentioned this pull request Jun 3, 2026
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 this pull request may close these issues.

Built-in caching while developing prevents smooth development Option to disable template caching in development

1 participant