Skip to content

feat: rich context typing for SliceZone component - #266

Open
wuguishifu wants to merge 2 commits into
prismicio:masterfrom
wuguishifu:master
Open

feat: rich context typing for SliceZone component#266
wuguishifu wants to merge 2 commits into
prismicio:masterfrom
wuguishifu:master

Conversation

@wuguishifu

@wuguishifu wuguishifu commented Jul 30, 2026

Copy link
Copy Markdown

Resolves:
N/A

Description

This PR introduces the ability to richly type a <SliceZone /> component, allowing for strict type checking to ensure that context parameters exist downstream in slices.

Right now, there's no way of statically guaranteeing that properties exist in the context which means you need to do additional defensive programming in each slice.

This change allows static analysis to catch any errors with missing context params much earlier in the dev flow.

Note: This feature will not break existing repos as the generic type is not required on the SliceZone component. Anyone who upgrades to a version of @prismicio/react with these changes will not have any type issues (this can be seen in ./examples/with-typescript/index.tsx:94

Checklist

  • If my changes require tests, I added them.
  • If my changes affect backward compatibility, it has been discussed.
  • If my changes require an update to the CONTRIBUTING.md guide, I updated it.

Preview

How to QA 1

This is a type-only change, so running npm run types should be enough to validate it.

🤓


Note

Low Risk
Type-only API tightening with backward-compatible defaults; no runtime logic changes beyond the existing context default.

Overview
Adds rich context typing for <SliceZone /> via a generic TContext, so slice components can rely on statically checked context instead of defensive checks at runtime.

SliceZoneProps now uses a conditional type: context stays optional when the default unknown context is used (existing call sites unchanged), but context is required when you pass a concrete type like <SliceZone<RichContext>>. The component is implemented as a generic function (SliceZone<T = never>) instead of React.FC, with the same runtime behavior (context still defaults to {}).

The TypeScript example adds WithContextRichSliceZone to document the pattern.

Reviewed by Cursor Bugbot for commit b5af010. Bugbot is set up for automated code reviews on this repo. Configure here.

Footnotes

  1. Please use these labels when submitting a review:
    ❓ #ask: Ask a question.
    💡 #idea: Suggest an idea.
    ⚠️ #issue: Strongly suggest a change.
    🎉 #nice: Share a compliment.

@wuguishifu wuguishifu changed the title feat: rich context typing for slice zone feat: rich context typing for SliceZone component Jul 30, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit bb38a8a. Configure here.

Comment thread src/SliceZone.tsx Outdated
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.

1 participant