Skip to content

feat: rich context typing for SliceZone component - #266

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

feat: rich context typing for SliceZone component#266
wuguishifu wants to merge 3 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
Compile-time-only API change with a default generic that preserves existing optional context usage.

Overview
SliceZone can now take a generic context type so slice components get a typed context prop and TypeScript can catch missing or wrong-shaped context at compile time.

SliceZoneProps uses a conditional type: context stays optional when no generic is used (same as today), but context is required when you pass something like SliceZone<RichContext>. The component is implemented as a generic function (SliceZone<T = never>) instead of FC<SliceZoneProps>, with no runtime behavior change.

The TypeScript example adds WithContextRichSliceZone to show the required context object when a context contract is declared.

Reviewed by Cursor Bugbot for commit 466fedb. 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