@tinkered/react 0.31.11 → 0.31.13

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.
package/README.md CHANGED
@@ -198,10 +198,12 @@ This appendix states each behaviour the seam tests pin, one line per promise, gr
198
198
  - The subtree uses the exact app-owned scope, which the provider never closes.
199
199
  - Under StrictMode, create mode leaks no scope and never exposes a closed one.
200
200
  - A new scope on the provider mounts its subtree again.
201
+ - A new starting root on the provider shows that root's values.
202
+ - An Activity hide closes the created scope; a show renders only with a fresh one.
201
203
 
202
204
  ### useScope
203
205
 
204
- - A hook used with no provider raises NoProvider.
206
+ - useScope, useResource, useRelease, and SessionProvider used with no provider raise NoProvider.
205
207
 
206
208
  ### useData
207
209
 
@@ -224,6 +226,8 @@ This appendix states each behaviour the seam tests pin, one line per promise, gr
224
226
  - A write after unmount neither updates the removed subtree nor breaks the still-open scope.
225
227
  - A component reads a keyed resource, keeps its reference across renders, and follows a write.
226
228
  - A new config leaves the old entry.
229
+ - A new cell with an inline selector shows and follows that cell.
230
+ - A server render gives a pair for writable options alone.
227
231
 
228
232
  ### useResource
229
233
 
@@ -240,6 +244,7 @@ This appendix states each behaviour the seam tests pin, one line per promise, gr
240
244
  - Reading through a new scope builds in the new scope.
241
245
  - A synchronous build commits on the first flushed render with no suspend.
242
246
  - The hook returns the exact instance core cached for the owner.
247
+ - Builds dropped by refetch that settle after the newest one never replace its result.
243
248
 
244
249
  ### Capsule components
245
250
 
@@ -278,6 +283,7 @@ This appendix states each behaviour the seam tests pin, one line per promise, gr
278
283
  - A run with only onSettled reports failure without onError.
279
284
  - A run with empty options resolves runAsync without callbacks.
280
285
  - onError and onSettled fire with the failure and the call.
286
+ - A run that settles while an Activity hides the view shows its result when shown again.
281
287
 
282
288
  ### SessionProvider
283
289
 
@@ -285,6 +291,7 @@ This appendix states each behaviour the seam tests pin, one line per promise, gr
285
291
  - Switching the parent scope never exposes the old session, even if the old parent is closed.
286
292
  - A session-target resource is one instance per SessionProvider; siblings are distinct.
287
293
  - A scope-target resource is the same instance across sibling sessions.
294
+ - An Activity hide closes the session; a show renders only with a fresh one.
288
295
 
289
296
  ### Namespace reset
290
297
 
@@ -298,6 +305,7 @@ This appendix states each behaviour the seam tests pin, one line per promise, gr
298
305
  - A chain refetch clears its head and reuses its fallback.
299
306
  - A named session can still refetch a shared scope resource.
300
307
  - An explicit reset key still releases a shared scope resource.
308
+ - A reset follows a new explicit key without remounting.
301
309
  - An independent borrowed scope clears an outer session's reset key.
302
310
  - An independent owned scope clears an outer session's reset key.
303
311
  - A field reset keeps the form owner, other fields, and hook identities.
package/dist/index.d.mts CHANGED
@@ -33,16 +33,22 @@ export type ScopeProviderProps = {
33
33
  /** Put a `@tinkered/core` scope on React context for the subtree. Hooks resolve against the nearest
34
34
  * provider's scope. This independent scope clears an outer React session's reset key. */
35
35
  export declare function ScopeProvider(props: ScopeProviderProps): ReactNode;
36
- /** Open a child session for a subtree: created on mount from the nearest scope, force-closed on
37
- * unmount — a React subtree's mount lifetime IS a session lifetime (ADR 0031). Hooks under it resolve
38
- * against the session (the nearest `Handle`), so a `data` write is shadowed and does not reach the
39
- * parent. Created in an effect (StrictMode-safe, like {@link ScopeProvider}'s `create` mode): a
40
- * discarded or replayed mount closes its own session and the next live mount opens a fresh one. The
41
- * session is published paired with the parent it belongs to; if the nearest scope changes, the old
42
- * session is never exposed for the new parent (render null until the effect opens a fresh one).
36
+ /** Open a child session for a subtree: created on mount from the nearest scope, force-closed at
37
+ * most one microtask after unmount — a React subtree's mount lifetime IS a session lifetime (ADR 0031). Hooks
38
+ * under it resolve against the session (the nearest `Handle`), so a `data` write is shadowed and does
39
+ * not reach the parent. Created in an effect (StrictMode-safe, like {@link ScopeProvider}'s `create`
40
+ * mode): StrictMode's first mount closes its session, which no render used yet, and the next live
41
+ * mount opens a fresh one; a replay after the children rendered keeps the session (see below). A
42
+ * new nearest scope mounts this provider again (ADR 0144), so a session is never shown under
43
+ * another parent.
43
44
  * The reset namespace head is saved with this session, including an inherited key.
44
45
  * `options` apply when the session is created — changing them for the same parent has no effect until
45
- * the provider remounts. */
46
+ * the provider remounts.
47
+ *
48
+ * A session its children never rendered with closes in the cleanup. A rendered one closes one
49
+ * microtask later: StrictMode replays the effect each time a `<Suspense>` shows this provider again,
50
+ * and that replay takes the same session back, so the children keep the data they loaded and do
51
+ * not suspend in a loop. A real unmount has no replay, so the session still closes. */
46
52
  export declare function SessionProvider(props: {
47
53
  readonly children: ReactNode;
48
54
  readonly options?: Scope.Options;
package/dist/index.mjs CHANGED
@@ -110,16 +110,22 @@ function ScopeProvider(props) {
110
110
  });
111
111
  return provide(value, props.children);
112
112
  }
113
- /** Open a child session for a subtree: created on mount from the nearest scope, force-closed on
114
- * unmount — a React subtree's mount lifetime IS a session lifetime (ADR 0031). Hooks under it resolve
115
- * against the session (the nearest `Handle`), so a `data` write is shadowed and does not reach the
116
- * parent. Created in an effect (StrictMode-safe, like {@link ScopeProvider}'s `create` mode): a
117
- * discarded or replayed mount closes its own session and the next live mount opens a fresh one. The
118
- * session is published paired with the parent it belongs to; if the nearest scope changes, the old
119
- * session is never exposed for the new parent (render null until the effect opens a fresh one).
113
+ /** Open a child session for a subtree: created on mount from the nearest scope, force-closed at
114
+ * most one microtask after unmount — a React subtree's mount lifetime IS a session lifetime (ADR 0031). Hooks
115
+ * under it resolve against the session (the nearest `Handle`), so a `data` write is shadowed and does
116
+ * not reach the parent. Created in an effect (StrictMode-safe, like {@link ScopeProvider}'s `create`
117
+ * mode): StrictMode's first mount closes its session, which no render used yet, and the next live
118
+ * mount opens a fresh one; a replay after the children rendered keeps the session (see below). A
119
+ * new nearest scope mounts this provider again (ADR 0144), so a session is never shown under
120
+ * another parent.
120
121
  * The reset namespace head is saved with this session, including an inherited key.
121
122
  * `options` apply when the session is created — changing them for the same parent has no effect until
122
- * the provider remounts. */
123
+ * the provider remounts.
124
+ *
125
+ * A session its children never rendered with closes in the cleanup. A rendered one closes one
126
+ * microtask later: StrictMode replays the effect each time a `<Suspense>` shows this provider again,
127
+ * and that replay takes the same session back, so the children keep the data they loaded and do
128
+ * not suspend in a loop. A real unmount has no replay, so the session still closes. */
123
129
  function SessionProvider(props) {
124
130
  const above = useBound("useScope");
125
131
  const parent = above.scope;
@@ -127,22 +133,41 @@ function SessionProvider(props) {
127
133
  const optionsRef = useRef(props.options);
128
134
  optionsRef.current = props.options;
129
135
  const [owned, setOwned] = useState(void 0);
136
+ const renderedRef = useRef(owned);
137
+ renderedRef.current = owned;
138
+ const releasedRef = useRef(void 0);
130
139
  useEffect(() => {
140
+ const released = releasedRef.current;
141
+ releasedRef.current = void 0;
142
+ if (released !== void 0) return () => release(released);
131
143
  const options = optionsRef.current;
132
144
  const session = parent.createSession(options);
133
145
  const ns = options?.ns;
134
146
  const [head] = ns === void 0 ? [inherited] : "tags" in ns ? [ns] : ns;
135
- setOwned({
136
- parent,
137
- bound: bind(session, head)
138
- });
139
- return () => {
140
- setOwned(void 0);
141
- closeScope(session);
142
- };
147
+ const next = bind(session, head);
148
+ setOwned(next);
149
+ return () => release(next);
143
150
  }, [parent, inherited]);
144
- if (owned === void 0 || owned.parent !== parent) return null;
145
- return provide(owned.bound, props.children);
151
+ /** Let go of the effect's session: close it now if no render used it, else hold it for the
152
+ * replay and close it in a microtask the replay did not cancel. That microtask also clears
153
+ * `owned`: an `<Activity>` that hides the provider runs this cleanup and keeps it mounted, so the
154
+ * hidden children must not keep the closed session; it shows a fresh one when the effect runs
155
+ * again. After an unmount React 19 ignores the state update. */
156
+ function release(current) {
157
+ if (renderedRef.current !== current) {
158
+ setOwned(void 0);
159
+ return closeScope(current.scope);
160
+ }
161
+ releasedRef.current = current;
162
+ queueMicrotask(() => {
163
+ if (releasedRef.current !== current) return;
164
+ releasedRef.current = void 0;
165
+ setOwned(void 0);
166
+ closeScope(current.scope);
167
+ });
168
+ }
169
+ if (owned === void 0) return null;
170
+ return provide(owned, props.children);
146
171
  }
147
172
  /** Read the nearest scope `Handle`. Raises `NoProvider` when used outside a {@link ScopeProvider}. */
148
173
  function useScope() {
@@ -365,7 +390,7 @@ function useResource(handle, options = QUERY_OPTIONS) {
365
390
  const ref = useRef(void 0);
366
391
  if (options.suspense !== false) return useSuspendedResource(scope, handle, ns);
367
392
  let owner = ref.current;
368
- if (owner === void 0 || owner.scope !== scope || owner.handle !== handle || owner.ns !== ns) owner = ref.current = new ResourceOwner(scope, handle, ns, force);
393
+ if (owner === void 0 || owner.handle !== handle || owner.ns !== ns) owner = ref.current = new ResourceOwner(scope, handle, ns, force);
369
394
  owner.inherited = inherited;
370
395
  return useQueryResource(owner);
371
396
  }
@@ -566,7 +591,7 @@ function useRun(op, options) {
566
591
  const [, force] = useReducer(RunOwner.bump, 0);
567
592
  const ref = useRef(void 0);
568
593
  let owner = ref.current;
569
- if (owner === void 0 || owner.scope !== scope || owner.op !== op) {
594
+ if (owner === void 0 || owner.op !== op) {
570
595
  if (owner !== void 0) owner.options = void 0;
571
596
  owner = ref.current = new RunOwner(scope, op, force);
572
597
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinkered/react",
3
- "version": "0.31.11",
3
+ "version": "0.31.13",
4
4
  "description": "Tinkered React: a thin React adapter over @tinkered/core.",
5
5
  "keywords": [
6
6
  "tanstack-intent"
@@ -29,12 +29,12 @@
29
29
  "access": "public"
30
30
  },
31
31
  "dependencies": {
32
- "@tinkered/core": "^0.31.11"
32
+ "@tinkered/core": "^0.31.13"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@stryker-mutator/core": "^10.0.0",
36
36
  "@stryker-mutator/vitest-runner": "^10.0.0",
37
- "@tinkered/core": "^0.31.11",
37
+ "@tinkered/core": "^0.31.13",
38
38
  "@types/node": "^26.1.1",
39
39
  "@types/react": "^19",
40
40
  "@types/react-dom": "^19",
@@ -15,7 +15,7 @@ metadata:
15
15
  type: framework
16
16
  framework: react
17
17
  library: '@tinkered/react'
18
- library_version: '0.31.11'
18
+ library_version: '0.31.13'
19
19
  requires:
20
20
  - '@tinkered/core#core'
21
21
  sources: