feat: rich context typing for SliceZone component - #266
Open
wuguishifu wants to merge 2 commits into
Open
Conversation
SliceZone component
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

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
SliceZonecomponent. Anyone who upgrades to a version of@prismicio/reactwith these changes will not have any type issues (this can be seen in./examples/with-typescript/index.tsx:94Checklist
Preview
How to QA 1
This is a type-only change, so running
npm run typesshould 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 genericTContext, so slice components can rely on statically checkedcontextinstead of defensive checks at runtime.SliceZonePropsnow uses a conditional type:contextstays optional when the defaultunknowncontext is used (existing call sites unchanged), butcontextis required when you pass a concrete type like<SliceZone<RichContext>>. The component is implemented as a generic function (SliceZone<T = never>) instead ofReact.FC, with the same runtime behavior (contextstill defaults to{}).The TypeScript example adds
WithContextRichSliceZoneto document the pattern.Reviewed by Cursor Bugbot for commit b5af010. Bugbot is set up for automated code reviews on this repo. Configure here.
Footnotes
Please use these labels when submitting a review:
⚠️ #issue: Strongly suggest a change.
❓ #ask: Ask a question.
💡 #idea: Suggest an idea.
🎉 #nice: Share a compliment. ↩