Commit f3757aa
committed
fix(core): share component registry across module instances
When the cli is installed globally (or hoisted at a different level
than the user's app), Node resolves `@webjskit/core` from each
importer's location and may load TWO instances of the package — one
for `@webjskit/server` (server-side) and one for the user's app
modules. Each instance had its own private `registry` Map, so:
user-app: ThemeToggle.register('theme-toggle') → instance-A registry
server: lookup('theme-toggle') → instance-B registry (empty)
SSR's `injectDSD` then skipped the tag and emitted bare
`<theme-toggle></theme-toggle>` even though the user registered it
correctly. The component appeared empty in the SSR'd HTML and only
"showed up" after browser hydration.
Fix: key the registry Map and class→tag WeakMap off `globalThis` with
`Symbol.for('webjs:registry')` / `Symbol.for('webjs:classToTag')`. Every
instance of the registry module now finds the same maps regardless of
how many copies of `@webjskit/core` are loaded.
Adds a regression test (`test/registry.test.js`) that loads the
registry module twice from distinct file URLs (simulating the dual-
install scenario) and asserts a registration in instance A is visible
to instance B's `allTags()`, `lookup()`, and `tagOf()`.
Versions:
- `@webjskit/core`: 0.1.0 → 0.2.0
- `@webjskit/server`: 0.2.0 → 0.2.1 (core pin updated)
- `@webjskit/cli`: 0.2.0 → 0.2.1 (server pin updated)1 parent 77f9e8e commit f3757aa
6 files changed
Lines changed: 96 additions & 12 deletions
File tree
- packages
- cli
- core
- src
- server
- test
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
20 | 48 | | |
21 | | - | |
| 49 | + | |
22 | 50 | | |
23 | | - | |
| 51 | + | |
24 | 52 | | |
25 | 53 | | |
26 | 54 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
0 commit comments