Skip to content
Source
Sign inSign up
TanStack/redact

fix: retain queued child and store work through Suspense #133

Opentannerlinsleywants to merge 1 commit intomain fromtaren/queued-store-approvedopened

tannerlinsleycommented

Fixes #75, fixes #120, fixes #129, fixes #130.

#92 remains open while its keyed Fragment wrapper case is investigated.

A parent that reuses JSX now keeps its own work while independently queued child state and context updates still run. Pending descendant work stays inside its Suspense boundary, and a retried primary tree can release its retained store update targets. This also prevents independently queued descendants from running against stale props after an ancestor suspends.

Thanks @yanissrairi for the ancestor batch guard idea in #129.

Validation includes cached children, nested context, hidden primary trees, fallback work, retained subscriptions, retry targets and feature-disabled bundles. The owned production browser cases cover Chromium, Firefox and WebKit against native React and main. These are minimal reported controls, not a claim that the original storefront app was tested.

Tanner approved the exact compatibility comparison rows, at most 181 bytes gzip and 176 bytes Brotli, and eight fixed gzip limit increases of 13 to 68 bytes. No other fixed limits change. The comparison allowance is bound to this source and baseline.

Summary by CodeRabbit

  • Bug Fixes

    • Child state and context updates are now applied when a parent reuses cached JSX, without unnecessarily rerendering unchanged components.
    • Queued updates are handled in tree order, and updates for children removed by a parent are discarded.
    • Updates to suspended content are retained and applied when the content becomes visible again.
    • Fixed context updates and external-store subscriptions in scenarios involving cached children and Suspense.
  • Tests

    • Added regression coverage for queued updates, context changes, Suspense behavior, and effect ordering.
    1. 🦋 Changeset detected

      Latest commit: c7c68465db1f08e435b0abc8be55d3d8e53a5887

      The changes in this PR will be included in the next version bump.

      This PR includes changesets to release 1 package
      NameType
      @tanstack/redactPatch

      Not sure what this means? Click here to learn what changesets are.

      Click here if you're a maintainer who wants to add another changeset to this PR

    2. Review in Change Stack →

      No actionable comments were generated in the recent review.

      Recent review info
      Run configuration
      • Source mode: Auto
      • Repository: Unavailable
      • Branch: Unavailable
      • File: No configuration file from this repository applied
      • Commit: Unavailable
      • Layers: defaults
      • Review profile: CHILL
      • Plan: Advanced
      • Run ID: b864f262-1157-4dda-9c9b-5f90351782c6
      Commits

      Reviewing files that changed from the base of the PR and between 70d534b44f9baa50628cd41373b5f66d634d714f and c7c68465db1f08e435b0abc8be55d3d8e53a5887.

      Files selected for processing: 22
      • .changeset/queued-descendant-updates.md
      • packages/redact/src/dom/features/context/full.ts
      • packages/redact/src/dom/features/suspense-pending/full.ts
      • packages/redact/src/dom/features/suspense-pending/index.ts
      • packages/redact/src/dom/features/suspense-pending/stub.ts
      • packages/redact/src/dom/features/suspense/full.ts
      • packages/redact/src/dom/reconcile.ts
      • packages/redact/src/vite/index.ts
      • scripts/compatibility-size-budget.d.mts
      • scripts/compatibility-size-budget.mjs
      • scripts/measure-size.mjs
      • scripts/size-check.mjs
      • tests/compatibility-size-budget.test.ts
      • tests/factory-context-discovery-contract.test.tsx
      • tests/factory-lifetime-contract.test.tsx
      • tests/factory-shadow-queue-contract.test.tsx
      • tests/issue120-cached-child.test.tsx
      • tests/issue75-stable-jsx.test.tsx
      • tests/queued-work-contract.test.tsx
      • tests/store-suspense-reports.test.tsx
      • tests/suspense-pending-feature.test.ts
      • tests/vite-plugin.test.ts

      Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 1 remain after this review.

      Walkthrough

      The PR changes DOM reconciliation to discover and process queued descendant work through cached JSX, and to defer descendants after a Suspense capture until boundary retry. It adds Suspense feature wiring and regression coverage. It also adds fingerprint-pinned queued-store allowances to compatibility size budgets.

      Changes: Queued descendant reconciliation

      Layer / File(s)Summary
      Pending-work discovery and feature wiring
      packages/redact/src/dom/reconcile.ts, packages/redact/src/dom/features/context/full.ts, packages/redact/src/dom/features/suspense-pending/*, packages/redact/src/vite/index.ts, scripts/measure-size.mjs, tests/suspense-pending-feature.test.ts, tests/vite-plugin.test.ts
      Reconciliation adds pending-work traversal and a capability predicate. The context and Suspense feature modules expose the predicate. Vite and size measurement recognize the Suspense pending-work feature and its disabled stub.
      Cached JSX and context updates
      packages/redact/src/dom/reconcile.ts, packages/redact/src/dom/features/context/full.ts, tests/factory-context-discovery-contract.test.tsx, tests/issue120-cached-child.test.tsx, tests/issue75-stable-jsx.test.tsx, tests/queued-work-contract.test.tsx, .changeset/queued-descendant-updates.md
      Stable function fibers can render pending descendants without rerendering themselves under the stated conditions. Context propagation uses the shared traversal. Tests cover cached children, context changes, and queued child updates. The changeset describes queued child state and context updates.
      Suspended batch ordering and retry
      packages/redact/src/dom/reconcile.ts, packages/redact/src/dom/features/suspense/full.ts, tests/factory-lifetime-contract.test.tsx, tests/factory-shadow-queue-contract.test.tsx, tests/store-suspense-reports.test.tsx
      Batch processing defers queued descendants of boundaries that suspend. Suspense retry resets primary-child update boundaries and restores prior targets if the retry suspends again. Tests cover queued work, effects, and external-store updates around Suspense.

      Queued-store size allowances

      Layer / File(s)Summary
      Fingerprint-pinned budget allowances
      scripts/compatibility-size-budget.mjs, scripts/compatibility-size-budget.d.mts, scripts/size-check.mjs, tests/compatibility-size-budget.test.ts
      The size-budget helpers fingerprint queued-store inputs and grant listed row allowances only when the base and fingerprint match. Size checks apply those allowances to the named rows. Tests cover supported metrics and mismatched approval inputs.

      Estimated code review effort: 3 (Moderate) | ~25 minutes

      Change: Bug fix · Severity of issue fixed: Medium

      Sequence Diagram(s)

      sequenceDiagram
        participant UpdateQueue
        participant renderUpdates
        participant SuspenseBoundary
        participant renderPendingChildren
        participant DescendantFiber
        UpdateQueue->>renderUpdates: deliver queued fibers
        renderUpdates->>SuspenseBoundary: schedule retry after a capture
        renderUpdates->>renderUpdates: skip queued descendants of the suspended boundary
        SuspenseBoundary->>renderPendingChildren: retry traversal
        renderPendingChildren->>DescendantFiber: render pending work

      Possibly related issues

      • TanStack/redact#129: The PR skips queued descendants after a boundary suspends and retries the boundary before processing those descendants.
      • TanStack/redact#120: The PR adds cached-child coverage and allows pending descendant work to proceed through stable fibers.
      • TanStack/redact#130: The pending-work traversal can reach scheduled descendants behind unchanged wrappers during a Suspense retry.
      • TanStack/redact#75: The PR adds a stable-fiber path that can render pending descendants without rerendering the unchanged function fiber.
      Merge Risk: Minimal · up to c7c68

      No actionable merge-blocking issue remains after normal checks.

      Pre-merge checks: Passed 3 · Failed 1 · Inconclusive 1
      Failed Failed checks: 1 warning · 1 inconclusive
      Check nameStatusExplanationResolution
      Docstring CoverageWarningDocstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…Write docstrings for the functions missing them to satisfy the coverage threshold.
      Linked Issues checkInconclusiveThe implementation and tests support #75, #120, #129, and #130. issue75-stable-jsx.test.tsx verifies that parent updates skip a cached subtree while child state and context updates still apply. `iss…Provide reviewable evidence for #92 that opening the Base UI menu preserves the original Menu.Trigger DOM node and prevents a lone mouseup on a menu item from activating it. A focused automated regression test or equivalent source-level…
      Passed Passed checks: 3 passed
      Check nameStatusExplanation
      Description CheckPassedCheck skipped - CodeRabbit’s high-level summary is enabled.
      Title checkPassedThe title clearly and concisely describes the main changes: retaining queued child and store work through Suspense.
      Out of Scope Changes checkPassedThe changes stay within the linked issue scope. Reconciliation changes, Suspense feature wiring, regression tests, feature-disabled bundle coverage, the changeset, and size-budget updates support the …
      Full details: Out of Scope Changes check

      Explanation

      The changes stay within the linked issue scope. Reconciliation changes, Suspense feature wiring, regression tests, feature-disabled bundle coverage, the changeset, and size-budget updates support the queued-work and Suspense fixes or document their approved compatibility impact. No unrelated product behavior is demonstrated.

      Full details: Docstring Coverage

      Explanation

      Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 24 functions across 21 files. (1 skipped: 1 unsupported.)

      Resolution

      Write docstrings for the functions missing them to satisfy the coverage threshold.

      Full details: Linked Issues check

      Explanation

      The implementation and tests support #75, #120, #129, and #130. issue75-stable-jsx.test.tsx verifies that parent updates skip a cached subtree while child state and context updates still apply. issue120-cached-child.test.tsx covers cached-child effects and state updates. store-suspense-reports.test.tsx covers stale-prop prevention and retained external-store work during Suspense retries. The available evidence does not directly establish #92's required Base UI Menu.Trigger DOM-node identity or its lone-mouseup behavior. No menu-specific regression test or focused browser result is present in the reviewable summary or inspected tests.

      Resolution

      Provide reviewable evidence for #92 that opening the Base UI menu preserves the original Menu.Trigger DOM node and prevents a lone mouseup on a menu item from activating it. A focused automated regression test or equivalent source-level evidence is needed to decide this requirement.

      Finishing Touches
      Generate docstrings
      • Commit to this branch
      • Create a new PR
      Generate unit tests (beta)
      • Commit to this branch
      • Create a new PR
      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

      Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

      Share
    3. #92 still reproduces on this branch (built at c7c6846), so fixes #92 would close it early.

      Smaller repro, no Base UI. This is the shape PopoverTrigger and MenuTrigger use: a keyed Fragment returned alone while closed, then wrapped between two focus guards while open.

      function Trigger() {
        const [open, setOpen] = useState(false)
        const keyed = <Fragment key="trigger"><button id="trigger" onClick={() => setOpen(true)}>open</button></Fragment>
        if (!open) return keyed
        return <><span tabIndex={0} />{keyed}<span tabIndex={0} /></>
      }

      After clicking #trigger:

      RuntimeSame <button> nodedocument.activeElement
      React 19.2yes#trigger
      Redact 0.2.4nobody
      Redact on this PRnobody

      The MutationObserver on the parent logs removed trigger, added before, added trigger, added after. React only logs added before, added after.

      Effect in an app: focus drops to body when a Base UI popover opens. Code that checks document.activeElement at that moment, or moves focus back into the trigger's container, lands on Base UI's pre-focus guard, and Base UI closes the popup right after it opens.

    4. Thanks @AlexisWalravens, that reproduction makes the missing case clear. I’ve removed #92 from this PR’s closing list and will keep it open while working on the Fragment transition.

      AI review notes: The reported case changes a single keyed Fragment into a child of an unkeyed Fragment with two focus guards. The existing queued-update controls do not establish node identity or focus preservation for that wrapper change.

      Fresh native React, main and candidate controls still need to check the exact button node, focus and parent mutations before a fix for #92 can be claimed. Those new controls have not been run yet.

    5. The size reduction work has a better tested candidate now. The remaining exact size decision has been requested.

      AI review notes: The current-main candidate adds at most 160 bytes gzip and 158 bytes Brotli, down from the earlier 174 and 203. It passes 2,098 tests, types, build verification and 126 fresh native React, baseline and candidate browser controls across Chromium, Firefox and WebKit. Two other approaches made Brotli larger and were rejected. Eleven fixed limits still need 8 to 68 extra gzip bytes, so the size gate remains closed pending the exact owner decision. This candidate has not been pushed to the PR yet. Issue 92 remains separate, this work covers issues 75, 120, 129 and 130.

    6. tannerlinsley linked this to fix #75, #120, #129, #130

Sign in to join this conversation.