Skip to content

fix: support react 19 context provider form - #27

Closed
letstri wants to merge 1 commit into
TanStack:mainfrom
letstri:fix/context-provider-form
Closed

letstri wants to merge 1 commit into
TanStack:mainfrom
letstri:fix/context-provider-form

Conversation

@letstri

@letstri letstri commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

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.

@coderabbitai

coderabbitai Bot commented Sep 11, 2026

Copy link
Copy Markdown

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 aa8730a and 9d6528a.

📒 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
Loading
sequenceDiagram
  participant RenderToString
  participant ContextElement
  participant ServerWalker
  RenderToString->>ContextElement: render value and children
  ContextElement->>ServerWalker: provide context marker
  ServerWalker-->>RenderToString: render children with context
Loading

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 name Status Explanation Resolution
Docstring Coverage ⚠️ Warning 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… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The 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.

@tannerlinsley

Copy link
Copy Markdown
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants