Skip to content
Source
Sign inSign up
TanStack/redact

fix: bubble errors from recovering class boundaries #109

MergedBleedingDev(GitHub profile, opens in a new tab)merged 4 commits intomain fromrefs/pull/109/headmerged by tannerlinsley

Why the change

Let an enclosing error boundary handle errors thrown by an inner boundary's fallback without losing the recovered content's hydrated Suspense range.

Special things to note

  • This is one commit directly on 052ca013262875d4a226095b1139bd83bf206bc8, with no dependency on the SSR ID or insertion-context PRs; recovery exclusions apply only while that boundary is rendering its fallback.
  • Full suite: 185 files and 2,008 tests passed, 91 skipped; types, build verification, and all 38 size gates passed. Source/built DOM-client gzip is 25,119/25,087 B; server stays at 8,975/8,974 B. Only the hydration-disabled entry needs a measured 72/81 B allowance, reaching 22,676/22,682 B.

Change outline

Reproduce with this tree in both CSR and hydration, where Thrower throws loader failure, Rethrow throws its received error, and ErrorPage renders an interactive counter:

<Suspense fallback={null}>
  <Boundary fallback={ErrorPage}>
    <Boundary fallback={Rethrow}>
      <Thrower />
    </Boundary>
  </Boundary>
</Suspense>

packages/redact/src/dom/features/class/full.ts:103 and :126 reconcile recovery while the same class remains eligible to catch child errors. packages/redact/src/dom/reconcile.ts:768 therefore retargeted the fallback's error to that inner class instead of the outer boundary.

 render recovery
+ enter this boundary's recovery scope
  derive fallback state and reconcile
- nearest error boundary can select this recovering class again
+ nearest error boundary skips recovering ancestors
+ newly nested boundaries can still catch
+ leave recovery scope in finally

 place hydrated recovery
- collect only new host nodes, outside the retained closing marker
+ collect opening marker, children and closing marker in order
+ preserve marker ownership through client recovery and deletion
regressions
  CSR and hydration fallback rethrows
  scheduled render errors and pre-captured commit errors
  different errors thrown by fallbacks
  boundaries introduced inside a fallback
  recovery cleanup and later boundary resets
  original sibling identity, marker containment and a working counter

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Errors thrown while an error boundary renders its recovery UI can now be handled by an enclosing boundary, including during updates and rendering.
    • Hydration recovery preserves Suspense boundary markers and surrounding content, preventing nearby content from being lost.
    • Error displays can update after recovery, and newly nested boundaries can catch errors raised by recovery UI.
    • Errors raised during recovery that have no enclosing boundary are reported, and can be caught by an enclosing boundary on a later render.
    1. changeset-bot[bot](GitHub profile, opens in a new tab)commented

      🦋 Changeset detected

      Latest commit: b4674ed5e4870dd95d9167393a8d3618d99be6c0

      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. Codex Review Summary

      This comment shows the latest Codex review activity on this pull request.

      ReviewStatusCommitReview trigger
      📝 Code Review🔄 Running since 2026-10-28T19:31:39.498938Z3811081PR opened
      ℹ️ About Codex in GitHub

      Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

      • Open a pull request for review
      • Mark a draft as ready
      • Comment "@codex review" or "@codex security review".

      Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

    3. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      Warning

      Review limit reached

      You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

      Next included review available in 17 minutes.

      Check out review usage here.

      View limit details

      Limit details: You’ve used all 4 included reviews currently available.

      Learn how review limits work.

      Review configuration:

      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: 9878a5da-e388-4c8a-b269-14247b8d0615
      Commits

      Reviewing files that changed from the base of the PR and between 495c622dedb39642fdcb8b05050d6ce16a653f72 and b4674ed5e4870dd95d9167393a8d3618d99be6c0.

      Files selected for processing: 1
      • tests/compatibility-size-budget.test.ts
      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: 6cf4fa07-42da-42f3-adfa-9ad9a5057717
      Commits

      Reviewing files that changed from the base of the PR and between 007831935105e0ae76118523690d120d1c369a9d and 495c622dedb39642fdcb8b05050d6ce16a653f72.

      Files selected for processing: 3
      • packages/redact/src/dom/features/class/full.ts
      • scripts/compatibility-size-budget.mjs
      • tests/compatibility-size-budget.test.ts

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

      Walkthrough

      The patch changes class error-boundary recovery so fallback errors can reach an enclosing boundary. It preserves Suspense markers during hydration recovery and removal. It also adds a fingerprint-pinned compatibility size allowance, with tests and a patch changeset.

      Changes: Boundary recovery

      Layer / File(s)Summary
      Error bubbling and validation
      packages/redact/src/core/internal.ts, packages/redact/src/dom/features/class/full.ts, packages/redact/src/dom/reconcile.ts, tests/error-boundary-recovery.test.tsx
      Class recovery marks the active fiber, and boundary lookup skips recovering ancestors. Tests cover client rendering, hydration, scheduled updates, commit-time errors, nested boundaries, and uncaught fallback errors.
      Suspense marker preservation and cleanup
      packages/redact/src/dom/features/suspense-hydration/full.ts, packages/redact/src/dom/reconcile.ts, .changeset/error-boundary-recovery.md
      Hydration retries retain the Suspense start and end markers. Host-node collection includes these markers, and removal deletes them when the boundary is not in state w. The changeset describes the recovery and marker changes.

      Compatibility size approval

      Layer / File(s)Summary
      Pinned recovery allowance and validation
      scripts/compatibility-size-budget.mjs, scripts/compatibility-size-budget.d.mts, tests/compatibility-size-budget.test.ts
      The script adds shared input fingerprinting and a PR109 allowance that applies only when the base and fingerprint match. Declarations and tests cover approved rows, metrics, mismatches, and fingerprint input changes.

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

      Change: Bug fix

      Sequence Diagram(s)

      sequenceDiagram
        participant renderClass
        participant Reconcile
        participant findErrorBoundary
        participant EnclosingBoundary
        renderClass->>Reconcile: render and reconcile recovery output
        Reconcile->>findErrorBoundary: locate a boundary for the captured error
        findErrorBoundary->>EnclosingBoundary: select an ancestor outside recovery

      Suggested reviewers: tannerlinsley

      Merge Risk: Low · previous review 495c6

      The error-bubbling change and the size allowance look sound. One test pins a fingerprint of the live checkout, so it will start failing after the release changeset is consumed or any listed input is edited. This is a bounded follow-up for the test gate and does not affect runtime behavior.

      Pre-merge checks: Passed 4 · Failed 1
      Failed Failed checks: 1 warning
      Check nameStatusExplanationResolution
      Docstring CoverageWarningDocstring coverage is 9.09% 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.
      Passed Passed checks: 4 passed
      Check nameStatusExplanation
      Description CheckPassedCheck skipped - CodeRabbit’s high-level summary is enabled.
      Title checkPassedThe title "fix: bubble errors from recovering class boundaries" matches the main change. The objectives say the PR lets an enclosing error boundary handle errors thrown by an inner class boundary's fa…
      Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck skipped because no linked issues were found for this pull request.
      Full details: Title check

      Explanation

      The title "fix: bubble errors from recovering class boundaries" matches the main change. The objectives say the PR lets an enclosing error boundary handle errors thrown by an inner class boundary's fallback, and the changes skip recovering boundaries in findErrorBoundary and add the fiber.br flag in renderClass. The title is short, specific, and uses the conventional fix: prefix. It does not cover the Suspense marker preservation, but that is a secondary part of the change.

      Full details: Docstring Coverage

      Explanation

      Docstring coverage is 9.09% 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 11 functions across 8 files.

      Resolution

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

      Finishing Touches
      Generate unit tests (beta)
      • 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
    4. This fixes a freeze we hit with TanStack Router, and it still reproduces on 0.2.4 and main (70d534b).

      The trigger is a route with both errorComponent and notFoundComponent. notFoundComponent wraps the route in CatchNotFound, whose inner CatchBoundary renders an errorComponent that rethrows every error that isn't a not-found error. When the loader throws, Redact sends that rethrown error back to the inner boundary instead of the route's own boundary. The boundary catches its own fallback's error again and again until flushPending throws flushPending exceeded 50 iterations — suspected infinite update loop. The tab freezes, and the route's error page never renders.

      Minimal router case (@tanstack/react-router 1.170.43):

      let failNext = false
      const rootRoute = createRootRoute({ loader: () => {
          if (failNext) {
            failNext = false
            throw new Error('Shell retry fixture')
          }
          return { ok: true } }, component: () => <Outlet />, notFoundComponent: () => <h1>Page not found</h1>, errorComponent: ({ reset }) => (
          <div>
            <h1>Something went wrong</h1>
            <button onClick={() => { reset(); router.invalidate() }}>Try again</button>
          </div> ),
      })
      
      // After the first render:
      failNext = true
      router.invalidate()

      I built each version from source with esbuild and ran it in headless Chromium:

      RuntimeResult
      React v19.3.0Error page renders, and "Try again" recovers
      Redact 0.2.0, 0.2.4, mainFreezes in the flushPending loop
      This PR (3811081)Error page renders, and "Try again" recovers, in production and development builds

      Without notFoundComponent, every Redact version renders the error page and recovers. The plain nested-boundary tree from the PR description also passes on 3811081.

      This branch now conflicts with main in packages/redact/src/dom/features/suspense/full.ts. #43 also fixes the router case, but this PR is the smaller change for this bug.

    5. tannerlinsleycommented

      Thanks @BleedingDev for the fix, and @LadyBluenotes for the router reproduction. The branch is updated for current main and is going through its remaining checks.

      AI review notes: Thanks @BleedingDev for the fix, and @LadyBluenotes for the router reproduction. I’ve merged current main into this branch and resolved the conflict against the split hydration implementation, preserving the recovery behavior and Suspense marker handling.

      Verified locally on 007831935105e0ae76118523690d120d1c369a9d:

      • 2,039 tests passed, 91 skipped, plus types and package build verification.
      • All 38 source and built-package size limits passed without raising those limits.
      • The official React compatibility size check passed with Tanner’s exact approved comparison rows, at most 109 bytes gzip and 139 bytes Brotli. The allowance is tied to this baseline and the tested source/build inputs.
      • Earlier real-router checks covered Chromium, Firefox and WebKit, development and production, with and without notFoundComponent. The recovery patch rendered the error page and the actual “Try again” action returned home, while main reproduced the freeze with notFoundComponent.

      My AI-assisted code and security review found no new material issue in this patch. GitHub’s checks on the updated head are the remaining delivery gate, I’ll merge once those pass.

    6. tannerlinsleycommented

      The size cost is lower now, and that smaller increase is approved to fix the freeze. The updated branch is going through its final checks.

      AI review notes: I took another pass at the size cost before landing this. Sharing the initial and recovery render path reduced the worst-case increase from 109 to 80 bytes gzip and from 139 to 99 bytes Brotli. Every comparison row stays within Tanner’s earlier approval, and I lowered the recorded allowances to the new measurements. No fixed size limit increases are needed.

      The smaller version at 495c622d passed 2,039 tests, types, build verification, all 38 fixed size limits and the official compatibility comparison. Fresh real-router checks also passed in Chromium, Firefox and WebKit, development and production, with notFoundComponent on and off. Both native React and this version rendered the error page and recovered to Home after the actual “Try again” click, with no uncaught errors.

      I reviewed the smaller code and security implications as well. The recovery guard still lets a failing fallback escape to its parent, and always clears after the attempt. The updated head is now waiting on its GitHub checks before merge.

      • Fix comments: Fix CodeRabbit comments on this PR
    7. tannerlinsley merged this577e376

    8. tannerlinsley closed this

    9. Thanks @BleedingDev for the fix, and @LadyBluenotes for the router reproduction. This is merged now.

      AI review notes: Merged at 577e3769002c467639878efe2218b2d16cc8aff6 after all 62 CI checks passed, security checks passed, and the review thread was resolved.

      The size pass reduced the worst-case increase from 109 to 80 bytes gzip and from 139 to 99 bytes Brotli. No fixed size limits were raised.

      One Firefox reload-interruption job passed on a single unchanged retry, including all 19 scenarios in Chromium, Firefox and WebKit. No assertions were relaxed. The original failure and native-control evidence were retained.

      This verifies the merged source. Published package verification remains a release follow-up.

Sign in to join this conversation.