Skip to content
Source
Sign inSign up
TanStack/redact

fix: support react 19 context provider form #27

Closedletstri(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/27/headopened

React 19 lets you render a context directly instead of <Ctx.Provider>. That form throws on the client and renders nothing on the server:

const Ctx = createContext('default')
const Read = () => <span>{useContext(Ctx)}</span>

createRoot(el).render(<Ctx value="provided"><Read /></Ctx>)
// InvalidCharacterError: The tag name provided ('[object Object]') is not a valid name

Summary by CodeRabbit

  • New Features

    • Context objects can now be rendered directly as providers using React 19 syntax, such as <Context value={...}>.
    • Context values propagate correctly to descendants during client rendering and server-side rendering.
    • Direct context providers work with consumers and can be combined with traditional provider syntax.
  • Bug Fixes

    • Fixed errors and missing context values when rendering contexts directly as elements.
    • Context updates now propagate correctly across re-renders.
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review Change StackReview Change Stack

      No actionable comments were generated in the recent review. 🎉

      ℹ️ Recent review info
      ⚙️ Run configuration

      Configuration used: defaults

      Review profile: CHILL

      Plan: Advanced

      Run ID: 76d24c59-dc11-462b-81d8-6a341b38d666

      📥 Commits

      Reviewing files that changed from the base of the PR and between aa8730af30298af691e75b2de73b6510200c2ddc and 9d6528a9f6ddeb93e3c37210e665bf1e63b0761d.

      📒 Files selected for processing (6)
      • .changeset/context-as-provider.md
      • packages/redact/src/dom/features/context/full.ts
      • packages/redact/src/dom/features/context/stub.ts
      • packages/redact/src/react/context.ts
      • packages/redact/src/server/walk.ts
      • tests/context-as-provider.test.tsx

      Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review.


      📝 Walkthrough

      Walkthrough

      This change lets a context object render as its own provider. Client and server renderers recognize the context marker. The context API exposes callable provider behavior. Tests cover propagation, updates, nested providers, consumers, and server rendering.

      Changes

      Context Provider Support

      Layer / File(s)Summary
      Context provider contract
      packages/redact/src/react/context.ts
      Context<T> now supports callable provider usage and stores a self-reference during createContext.
      Client context rendering
      packages/redact/src/dom/features/context/*, tests/context-as-provider.test.tsx
      Client fiber matching recognizes context elements as providers or fragments. Tests cover value propagation, updates, nested providers, and consumers.
      Server context rendering
      packages/redact/src/server/walk.ts, tests/context-as-provider.test.tsx, .changeset/context-as-provider.md
      The server walker processes context-marked elements as providers. Server-rendering coverage and the patch changeset document the behavior.

      Priority: ➖ Normal

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

      Change: Bug fix · Severity of issue fixed: Medium

      Sequence Diagram(s)

      sequenceDiagram
        participant ReactRoot
        participant ContextElement
        participant ClientReconciler
        participant ContextConsumer
        ReactRoot->>ContextElement: render value and children
        ContextElement->>ClientReconciler: provide context marker
        ClientReconciler->>ContextConsumer: propagate value
        ContextConsumer-->>ReactRoot: render descendant output
      sequenceDiagram
        participant RenderToString
        participant ContextElement
        participant ServerWalker
        RenderToString->>ContextElement: render value and children
        ContextElement->>ServerWalker: provide context marker
        ServerWalker-->>RenderToString: render children with context

      Suggested reviewers: tannerlinsley

      Merge Risk: ⚪ Minimal · up to 9d652

      Direct context-provider rendering is implemented consistently across the public API, client paths, and server rendering, with relevant test coverage. No merge-blocking risk is evident.

      🚥 Pre-merge checks | ✅ 4 | ❌ 1

      ❌ Failed checks (1 warning)

      Check nameStatusExplanationResolution
      Docstring Coverage⚠️ WarningDocstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 5 files. (1 skipped: 1…Write docstrings for the functions missing them to satisfy the coverage threshold.
      ✅ Passed checks (4 passed)
      Check nameStatusExplanation
      Linked Issues check✅ PassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes check✅ PassedCheck skipped because no linked issues were found for this pull request.
      Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
      Title check✅ PassedThe title clearly and concisely describes the main change: support for React 19's direct context provider form.
      Full details: Docstring Coverage

      Explanation

      Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 5 files. (1 skipped: 1 unsupported.)

      • Fix all pre-merge checks with AI
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create PR with unit tests

      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
      Comment `@coderabbitai help` to get the list of available commands.
    2. Thanks for the fix, Valerii. Direct context providers are now merged in #29, with your co-author credit and client, SSR, hydration, size, and performance coverage. Closing this in favor of the merged PR.

    3. tannerlinsley closed this

Sign in to join this conversation.