Skip to content

Commit

Permalink
Make Fragment symbol comparable across module instances (#36)
Browse files Browse the repository at this point in the history
When debugging Forgo using `npm link`, Vite's pre-bundling optimization executes the `forgo` module twice ([Vite bug](vitejs/vite#3910), [Svelte bug with workarounds](sveltejs/vite-plugin-svelte#135 (comment))). It doesn't happen when using the package from npm.

This results in different code paths holding references to two different `Fragment` symbols, causing renders to fail because the two symbols aren't comparable using `===`. Using `Symbol.for()` makes all symbols named `FORGO_FRAGMENT` comparable, no matter where they come from.

Alternatively, there's a workaround to have Vite disable pre-bundling optimizations for `forgo`, but this patch makes that unnecessary.
  • Loading branch information
spiffytech committed Jan 14, 2022
1 parent 22e5c70 commit 2bd8293
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ export type RenderResult = {
Fragment constructor.
We simply use it as a marker in jsx-runtime.
*/
export const Fragment: unique symbol = Symbol("FORGO_FRAGMENT");
export const Fragment: unique symbol = Symbol.for("FORGO_FRAGMENT");

/*
HTML Namespaces
Expand Down

0 comments on commit 2bd8293

Please sign in to comment.