@tinkered/react 0.31.8 → 0.31.10

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
@@ -250,7 +250,7 @@ This appendix states each behaviour the seam tests pin, one line per promise, gr
250
250
  ### useRun
251
251
 
252
252
  - A parent render keeps the run handle when no run changed.
253
- - StrictMode clears the run from its discarded effect mount.
253
+ - StrictMode keeps the run from its replayed effect mount.
254
254
  - A cancelled run rejects with the caller's exact reason.
255
255
 
256
256
  - Normal calls and omitted callbacks report no host error.
@@ -262,7 +262,7 @@ This appendix states each behaviour the seam tests pin, one line per promise, gr
262
262
  - A failing operation stays in error state and does not throw to an error boundary.
263
263
  - A handled operation panic stays in error state and the root closes successfully.
264
264
  - Switching providers clears the previous run state.
265
- - Switching providers drops late results and callbacks; the caller still gets its value.
265
+ - Switching providers mounts the view again: the old run fires its callbacks but never shows.
266
266
  - Switching operations drops late results and callbacks from the old operation.
267
267
  - Reset from a success clears status, data, and error.
268
268
  - Reset from an error clears status, data, and error.
package/dist/index.d.mts CHANGED
@@ -187,8 +187,12 @@ export declare namespace Run {
187
187
  * with `variables` = the call), `runAsync(input)` also returns the value or rejects, `reset()`
188
188
  * returns to idle. A rejection never reaches an error boundary (that is {@link useResource}'s job).
189
189
  * Only the latest run publishes state: a slower earlier run that settles after a newer one (or after
190
- * `reset`) is dropped, though its `options` callbacks still fire. Changing the provider or operation
191
- * clears the view and stops the old owner's state and callback writes; its caller still gets the result.
190
+ * `reset`) is dropped, though its `options` callbacks still fire. A Suspense hide and show keeps the
191
+ * latest state; a run that settles while hidden or after unmount still fires its callbacks once.
192
+ * Changing the operation clears the view: a new owner starts idle, and the old owner's runs fire no
193
+ * callbacks; they still write the old owner's state, which is never shown again. Changing the provider
194
+ * mounts the subtree again (ADR 0144), so the view starts idle and the old run fires its callbacks as
195
+ * after an unmount. Either way its caller still gets the result.
192
196
  * Handled failures are received through Core's `settle`, so a panic does not fail the owner. */
193
197
  export declare function useRun<T, I>(op: Operation.Handle<T, I>, options?: Run.Options<Awaited<T>, I>): Run.Handle<Awaited<T>, I>;
194
198
  /** Reset a node in an explicit namespace, or the nearest React session's saved namespace head.
package/dist/index.mjs CHANGED
@@ -452,7 +452,9 @@ function reportCallbackError(error) {
452
452
  throw error;
453
453
  });
454
454
  }
455
- /** Each committed hook owns its view; old calls keep their result but lose publication on detach. */
455
+ /** Each committed hook owns its view (ADR 0032 d2). Hidden or unmounted, it keeps the latest state
456
+ * without a re-render, and every run still fires its callbacks; a show renders that state. A replaced
457
+ * owner loses its `options`, so its old calls keep their result but fire no callbacks. */
456
458
  var RunOwner = class RunOwner {
457
459
  static idle = {
458
460
  status: "idle",
@@ -478,9 +480,10 @@ var RunOwner = class RunOwner {
478
480
  this.op = op;
479
481
  this.force = force;
480
482
  }
483
+ /** A state written while detached has no handle yet: render it. */
481
484
  attach = () => {
482
485
  this.live = true;
483
- if (this.state !== RunOwner.idle) this.publish(RunOwner.idle);
486
+ if (this.cached === void 0) this.force();
484
487
  return () => {
485
488
  this.live = false;
486
489
  };
@@ -497,22 +500,21 @@ var RunOwner = class RunOwner {
497
500
  };
498
501
  reset = () => {
499
502
  this.runId += 1;
500
- if (this.live) this.publish(RunOwner.idle);
503
+ this.publish(RunOwner.idle);
501
504
  };
505
+ /** Only a live view re-renders: no React state write while hidden or after unmount. */
502
506
  publish(state) {
503
507
  this.state = state;
504
508
  this.cached = void 0;
505
- this.force();
509
+ if (this.live) this.force();
506
510
  }
507
511
  finish(id, result, variables) {
508
512
  const outcome = readRunOutcome(result);
509
- if (this.live) {
510
- if (this.runId === id) this.publish({
511
- ...settledState(outcome),
512
- variables
513
- });
514
- notify(this.options, outcome, variables);
515
- }
513
+ if (this.runId === id) this.publish({
514
+ ...settledState(outcome),
515
+ variables
516
+ });
517
+ notify(this.options, outcome, variables);
516
518
  return outcome;
517
519
  }
518
520
  invoke(call) {
@@ -521,7 +523,7 @@ var RunOwner = class RunOwner {
521
523
  const [variables] = call;
522
524
  const result = this.controller.settle(...call);
523
525
  if (!(result instanceof Promise)) return this.finish(id, result, variables);
524
- if (this.live && this.runId === id) this.publish({
526
+ if (this.runId === id) this.publish({
525
527
  status: "pending",
526
528
  data: void 0,
527
529
  error: void 0,
@@ -551,8 +553,12 @@ var RunOwner = class RunOwner {
551
553
  * with `variables` = the call), `runAsync(input)` also returns the value or rejects, `reset()`
552
554
  * returns to idle. A rejection never reaches an error boundary (that is {@link useResource}'s job).
553
555
  * Only the latest run publishes state: a slower earlier run that settles after a newer one (or after
554
- * `reset`) is dropped, though its `options` callbacks still fire. Changing the provider or operation
555
- * clears the view and stops the old owner's state and callback writes; its caller still gets the result.
556
+ * `reset`) is dropped, though its `options` callbacks still fire. A Suspense hide and show keeps the
557
+ * latest state; a run that settles while hidden or after unmount still fires its callbacks once.
558
+ * Changing the operation clears the view: a new owner starts idle, and the old owner's runs fire no
559
+ * callbacks; they still write the old owner's state, which is never shown again. Changing the provider
560
+ * mounts the subtree again (ADR 0144), so the view starts idle and the old run fires its callbacks as
561
+ * after an unmount. Either way its caller still gets the result.
556
562
  * Handled failures are received through Core's `settle`, so a panic does not fail the owner. */
557
563
  function useRun(op, options) {
558
564
  const scope = useScope();
@@ -560,7 +566,10 @@ function useRun(op, options) {
560
566
  const [, force] = useReducer(RunOwner.bump, 0);
561
567
  const ref = useRef(void 0);
562
568
  let owner = ref.current;
563
- if (owner === void 0 || owner.scope !== scope || owner.op !== op) owner = ref.current = new RunOwner(scope, op, force);
569
+ if (owner === void 0 || owner.scope !== scope || owner.op !== op) {
570
+ if (owner !== void 0) owner.options = void 0;
571
+ owner = ref.current = new RunOwner(scope, op, force);
572
+ }
564
573
  owner.options = options;
565
574
  useLayoutEffect(owner.attach, [owner]);
566
575
  return owner.handle();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinkered/react",
3
- "version": "0.31.8",
3
+ "version": "0.31.10",
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.8"
32
+ "@tinkered/core": "^0.31.10"
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.8",
37
+ "@tinkered/core": "^0.31.10",
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.8'
18
+ library_version: '0.31.10'
19
19
  requires:
20
20
  - '@tinkered/core#core'
21
21
  sources: