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

fix(hmr): allow changes to component decorators when using HMR #5290

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/client/client-host-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,21 @@ import type * as d from '../declarations';
/**
* A WeakMap mapping runtime component references to their corresponding host reference
* instances.
*
* **Note**: If we're in an HMR context we need to store a reference to this
* value on `window` in order to maintain the mapping of {@link d.RuntimeRef}
* to {@link d.HostRef} across HMR updates.
*
* This is necessary because when HMR updates for a component are processed by
* the browser-side dev server client the JS bundle for that component is
* re-fetched. Since the module containing {@link hostRefs} is included in
* that bundle, if we do not store a reference to it the new iteration of the
* component will not have access to the previous hostRef map, leading to a
* bug where the new version of the component cannot properly initialize.
*/
const hostRefs: WeakMap<d.RuntimeRef, d.HostRef> = /*@__PURE__*/ new WeakMap();
const hostRefs: WeakMap<d.RuntimeRef, d.HostRef> = /*@__PURE__*/ BUILD.hotModuleReplacement
? ((window as any).__STENCIL_HOSTREFS__ ||= new WeakMap())
: new WeakMap();

/**
* Given a {@link d.RuntimeRef} retrieve the corresponding {@link d.HostRef}
Expand Down