feat: add HMR support for pion components via Vite plugin#98
Draft
cristinecula wants to merge 1 commit into
Draft
feat: add HMR support for pion components via Vite plugin#98cristinecula wants to merge 1 commit into
cristinecula wants to merge 1 commit into
Conversation
Add hot module replacement infrastructure that enables swapping pion component renderers on live DOM instances without full page reloads. - Add HMR runtime (src/hmr.ts) with component registry, instance tracking, and renderer hot-swap via patched customElements.define - Add Vite plugin (src/vite-plugin.ts) that injects enableHMR() preamble and appends import.meta.hot.accept() to component files - Modify component.ts to store renderer on Element class via Symbol and track/untrack instances in connected/disconnected callbacks - Add rendererSymbol and hmrTagSymbol to symbols.ts - Add package.json exports for ./hmr and ./vite-plugin subpaths - Add HMR test suite covering registration, instance tracking, renderer replacement, state preservation, and re-define handling
✅ Deploy Preview for pionjs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
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.
Summary
Architecture
The implementation has three parts:
1. HMR Runtime (
src/hmr.ts){ renderer, elementClass, instances }enableHMR()patchescustomElements.defineto intercept pion component registrationsdefinecall: registers normally + tracks in registrydefinecalls (same tag): extracts new renderer viarendererSymbol, swaps it on all live instances via_scheduler.renderer, triggers_scheduler.update()2. Component integration (
src/component.ts,src/symbols.ts)rendererSymbolstored on each Element class so the HMR runtime can extract ithmrTagSymbolset on prototypes so instances self-register inconnectedCallback/disconnectedCallbackisHMRActive()is true (zero overhead in production)3. Vite Plugin (
src/vite-plugin.ts)transformIndexHtml: injects<script type="module">preamble that callsenableHMR()before app code loadstransform: detects files matchingcustomElements.define('tag', component(...))and appendsimport.meta.hot.accept()vite serve(no effect on production builds)Usage
No changes needed in component files.
Known limitations
component()— Polymer/legacy components are not hot-replaceableobservedAttributeschanges during HMR won't take effect (read once by the browser at define time)Tests
Added
test/hmr.test.tscovering: