@timber-js/app 0.1.56 → 0.2.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -93,33 +93,25 @@ function useLinkStatus() {
93
93
  * that depend on these APIs are safe to call from any environment —
94
94
  * they return null or no-op when the APIs aren't available.
95
95
  *
96
+ * Singleton guarantee: With the simplified chunking strategy (LOCAL-337),
97
+ * this module lives in exactly one client chunk. The previous globalThis +
98
+ * Symbol.for workaround for cross-chunk duplication is no longer needed.
99
+ * See design/27-chunking-strategy.md.
100
+ *
96
101
  * See design/19-client-navigation.md §"NavigationContext"
97
102
  */
98
103
  /**
99
104
  * The context is created lazily to avoid calling createContext at module
100
105
  * level. In the RSC environment, React.createContext doesn't exist —
101
106
  * calling it at import time would crash the server.
102
- *
103
- * IMPORTANT: Context instances are stored on globalThis, NOT in module-
104
- * level variables. The RSC client bundler duplicates this module across
105
- * the browser-entry chunk (index) and client-reference chunk (shared-app)
106
- * because both entry graphs import it. Module-level variables would create
107
- * separate singleton instances per chunk — the provider in TransitionRoot
108
- * (index chunk) would use context A while the consumer in LinkStatusProvider
109
- * (shared-app chunk) reads from context B. globalThis guarantees a single
110
- * instance regardless of how many times the module is duplicated.
111
- *
112
- * See design/19-client-navigation.md §"Singleton Context Guarantee"
113
107
  */
114
- var NAV_CTX_KEY = Symbol.for("__timber_nav_ctx");
115
- var PENDING_CTX_KEY = Symbol.for("__timber_pending_nav_ctx");
108
+ var _navCtx;
109
+ var _pendingNavCtx;
116
110
  function getOrCreateContext() {
117
- const existing = globalThis[NAV_CTX_KEY];
118
- if (existing !== void 0) return existing;
111
+ if (_navCtx !== void 0) return _navCtx;
119
112
  if (typeof React.createContext === "function") {
120
- const ctx = React.createContext(null);
121
- globalThis[NAV_CTX_KEY] = ctx;
122
- return ctx;
113
+ _navCtx = React.createContext(null);
114
+ return _navCtx;
123
115
  }
124
116
  }
125
117
  /**
@@ -152,42 +144,27 @@ function NavigationProvider({ value, children }) {
152
144
  * NavigationProvider with the correct params/pathname.
153
145
  *
154
146
  * This is NOT used by hooks directly — hooks read from React context.
155
- *
156
- * Stored on globalThis (like the context instances above) because the
157
- * router lives in the shared-app chunk while renderRoot lives in the
158
- * index chunk. Module-level variables would be separate per chunk.
159
147
  */
160
- var NAV_STATE_KEY = Symbol.for("__timber_nav_state");
161
- function _getNavStateStore() {
162
- const g = globalThis;
163
- if (!g[NAV_STATE_KEY]) g[NAV_STATE_KEY] = { current: {
164
- params: {},
165
- pathname: "/"
166
- } };
167
- return g[NAV_STATE_KEY];
168
- }
148
+ var _navState = {
149
+ params: {},
150
+ pathname: "/"
151
+ };
169
152
  function setNavigationState(state) {
170
- _getNavStateStore().current = state;
153
+ _navState = state;
171
154
  }
172
155
  function getNavigationState() {
173
- return _getNavStateStore().current;
156
+ return _navState;
174
157
  }
175
158
  /**
176
159
  * Separate context for the in-flight navigation URL. Provided by
177
160
  * TransitionRoot (urgent useState), consumed by LinkStatusProvider
178
161
  * and useNavigationPending.
179
- *
180
- * Uses globalThis via Symbol.for for the same reason as NavigationContext
181
- * above — the bundler duplicates this module across chunks, and module-
182
- * level variables would create separate context instances.
183
162
  */
184
163
  function getOrCreatePendingContext() {
185
- const existing = globalThis[PENDING_CTX_KEY];
186
- if (existing !== void 0) return existing;
164
+ if (_pendingNavCtx !== void 0) return _pendingNavCtx;
187
165
  if (typeof React.createContext === "function") {
188
- const ctx = React.createContext(null);
189
- globalThis[PENDING_CTX_KEY] = ctx;
190
- return ctx;
166
+ _pendingNavCtx = React.createContext(null);
167
+ return _pendingNavCtx;
191
168
  }
192
169
  }
193
170
  /**