Repository navigation
Refactor HMR: on/off switch (default off) and reload fixes - #20
Open
lschirmbrand wants to merge 1 commit into
Open
lschirmbrand wants to merge 1 commit into
lschirmbrand wants to merge 1 commit into
Conversation
lschirmbrand
commented
Oct 9, 2026
Contributor
- Add enabled switch (?hmr=on|off, localStorage, API, showToggle()), default off
- Restore customElements.define in finally, keep polling after errors
- Match instances by class identity, patch classes via property descriptors
- Remove deleted members, fix Function.style pollution
- Resolve reload paths against the page
- Swap templates for all components when the template changed, redo bindings/events with the original options, swap styles in place
- Add enabled switch (?hmr=on|off, localStorage, API, showToggle()), default off - Restore customElements.define in finally, keep polling after errors - Match instances by class identity, patch classes via property descriptors - Remove deleted members, fix Function.style pollution - Resolve reload paths against the page - Swap templates for all components when the template changed, redo bindings/events with the original options, swap styles in place Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes recommended
Polling bypass, stylesheet update bugs, accessibility, and listener cleanup issues remain.
5 open findings
What changed in this PR
Refactors HMR to support opt-in polling, safer module patching, and improved template/style replacement.
Changes:
- Adds persistent HMR enable/disable controls and UI toggle.
- Improves polling resilience, module patching, and path resolution.
- Rebuilds templates, bindings, events, and styles during reloads.
| File | Description |
|---|---|
src/HotModuleReplacement.ts |
Implements controls and reload behavior. |
src/BaseCustomWebComponent.ts |
Retains binding and event setup state. |
README.md |
Documents HMR controls and path requirements. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| button.setAttribute('aria-checked', String(HotModuleReplacement.enabled)); | ||
| }; | ||
| button.addEventListener('click', () => HotModuleReplacement.toggle()); | ||
| window.addEventListener('hmr-enabled-changed', update); |
Comment on lines
147
to
+149
| public static startPolling(interval = 100) { | ||
| setTimeout(() => { | ||
| HotModuleReplacement.pollForChanges(interval); | ||
| }, interval); | ||
| HotModuleReplacement.interval = interval; | ||
| HotModuleReplacement.schedule(); |
Comment on lines
+282
to
+284
| const idx = current.findIndex(x => oldSheets.includes(x)); | ||
| if (idx < 0) | ||
| return; |
| const newCssModule = await import(url + "?reload=" + newId, { with: { type: 'css' } }); | ||
| const oldStylesheet: CSSStyleSheet = oldCssModule.default; | ||
| const newStylesheet: CSSStyleSheet = newCssModule.default; | ||
| oldStylesheet.replace(Array.from(newStylesheet.cssRules).map(rule => rule.cssText).join('')); |
Comment on lines
+109
to
+112
| button { all: unset; cursor: pointer; display: flex; align-items: center; gap: 8px; padding: 6px 12px 6px 8px; | ||
| font: 12px system-ui, sans-serif; color: #fff; background: #333; border-radius: 16px; opacity: .85; | ||
| box-shadow: 0 2px 6px rgba(0,0,0,.35); } | ||
| button:hover { opacity: 1; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

