Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support React Server Components #178

Merged
merged 25 commits into from
May 6, 2023
Merged

feat: support React Server Components #178

merged 25 commits into from
May 6, 2023

Conversation

angeloashmore
Copy link
Member

@angeloashmore angeloashmore commented Apr 6, 2023

Types of changes

  • Chore (a non-breaking change which is related to package maintenance)
  • Bug fix (a non-breaking change which fixes an issue)
  • New feature (a non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Description

This PR adds support for React Server Components (RSC).

RSC-compatible versions of components are provided automatically when used in Server Components.

This PR makes use of @prismicio/client v7. It is marked as a dependency, not a peer dependency, to be compatible with apps that have not updated to v7.

APIs modified for Server Components

  • <PrismicLink>: No longer supports global configuration for internalLinkComponent, externalLinkComponent, and linkResolver.
  • <PrismicRichText>: No longer supports global configuration for richTextComponents.

APIs provided unmodified

  • <PrismicImage>
  • <PrismicText>
  • <PrismicToolbar>
  • <SliceZone>

Note regarding <PrismicToolbar>: Prefer using a framework-specific <script> component along with @prismicio/client's getToolbarSrc() instead. <PrismicToolbar> will continue to be provided, but it is probably not the most optimal solution for application with server-side build- and run-times.

APIs not supported in Server Components

  • <PrismicProvider>: Global configuration is no longer possible; React Context is not supported in RSCs.
  • All content query hooks: Server Components allow the use of async/await and @prismicio/client directly.

How to use

This PR is a work in progress. Once the API matures, a guide on using @prismicio/react with React Server Components will be provided.

Until the PR is merged, all APIs and names are unstable and may change.

Checklist:

  • My change requires an update to the official documentation.
  • All TSDoc comments are up-to-date and new ones have been added where necessary.
  • All new and existing tests are passing.

🐱

@github-actions
Copy link

github-actions bot commented Apr 6, 2023

size-limit report 📦

Path Size
dist/index.js 0 B (-100% 🔽)
dist/index.cjs 0 B (-100% 🔽)
./dist/index.cjs 7.89 KB (+100% 🔺)
./dist/index.js 5.45 KB (+100% 🔺)
./dist/react-server.cjs 7 KB (+100% 🔺)
./dist/react-server.js 4.95 KB (+100% 🔺)

@codecov-commenter
Copy link

codecov-commenter commented Apr 6, 2023

Codecov Report

Merging #178 (2e5ffac) into master (e6e05a3) will decrease coverage by 0.06%.
The diff coverage is 99.48%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##           master     #178      +/-   ##
==========================================
- Coverage   99.29%   99.23%   -0.06%     
==========================================
  Files          18       21       +3     
  Lines        2426     2367      -59     
  Branches      133      125       -8     
==========================================
- Hits         2409     2349      -60     
- Misses         17       18       +1     
Impacted Files Coverage Δ
src/PrismicRichText.tsx 94.73% <92.85%> (-4.65%) ⬇️
src/react-server/PrismicRichText.tsx 99.25% <99.25%> (ø)
src/PrismicImage.tsx 100.00% <100.00%> (ø)
src/PrismicLink.tsx 100.00% <100.00%> (ø)
src/PrismicProvider.tsx 100.00% <100.00%> (ø)
src/PrismicText.tsx 100.00% <100.00%> (ø)
src/PrismicToolbar.tsx 100.00% <100.00%> (ø)
src/SliceZone.tsx 97.60% <100.00%> (-0.88%) ⬇️
src/index.ts 100.00% <100.00%> (ø)
src/react-server/PrismicLink.tsx 100.00% <100.00%> (ø)
... and 2 more

... and 1 file with indirect coverage changes

@angeloashmore angeloashmore changed the title feat: add @prismicio/react/rsc entry with React Server Components support feat: add React Server Components support Apr 22, 2023
@angeloashmore angeloashmore changed the title feat: add React Server Components support feat: support React Server Components Apr 24, 2023
@angeloashmore angeloashmore merged commit ea0ddf8 into master May 6, 2023
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