prismicio / prismic-react

React components and hooks to fetch and present Prismic content
https://prismic.io/docs/technologies/homepage-reactjs
Apache License 2.0
153 stars 40 forks source link

feat: support React Server Components #178

Closed angeloashmore closed 12 months ago

angeloashmore commented 1 year ago

Types of changes

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

APIs provided unmodified

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

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:

🐱

github-actions[bot] commented 1 year ago

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 commented 1 year ago

Codecov Report

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

:mega: 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%) :arrow_down:
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%) :arrow_down:
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