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

fix(PrismicImage): allow removing Imgix params in React Server Components using `null` #188

Closed angeloashmore closed 10 months ago

angeloashmore commented 10 months ago

Types of changes

Description

This PR fixes a case where <PrismicImage> would not remove Imgix parameters when used in React Server Components (RSC).

RSCs serialize prop values before sending to Client Compomnents like <PrismicImage>. During this serialization, undefined values are removed from objects, which <PrismicImage>'s underlying Imgix param library, imgix-url-builder, relies on to remove parameters.

To fix this, imgixParams now accepts null in place of undefined.

null should be used to remove parameters when <PrismicImage> is used in Server Components.

// In a Server Component
<PrismicImage
  field={myImageField}
  imgixParams={{
    auto: null, // undefined will not work
  }}
/>
// In a Client Component
<PrismicImage
  field={myImageField}
  imgixParams={{
    auto: undefined, // null can also be used
  }}
/>

Checklist:

github-actions[bot] commented 10 months ago

size-limit report 📦

Path Size
./dist/index.cjs 8.02 KB (+0.2% 🔺)
./dist/index.js 6.05 KB (+0.33% 🔺)
./dist/react-server.cjs 7.21 KB (+0.17% 🔺)
./dist/react-server.js 5.57 KB (+0.27% 🔺)
codecov-commenter commented 10 months ago

Codecov Report

Merging #188 (e7bcada) into master (323d6fc) will increase coverage by 0.00%. The diff coverage is 100.00%.

:exclamation: Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

@@           Coverage Diff           @@
##           master     #188   +/-   ##
=======================================
  Coverage   99.68%   99.68%           
=======================================
  Files          20       20           
  Lines        2555     2561    +6     
  Branches       93       95    +2     
=======================================
+ Hits         2547     2553    +6     
  Misses          8        8           
Impacted Files Coverage Δ
src/PrismicImage.tsx 100.00% <100.00%> (ø)