Skip to content

Commit

Permalink
Add a workaround for Next.js production build bug (#421)
Browse files Browse the repository at this point in the history
* Add a workaround for Next.js production build bug

Workaround for a Next.js bug when generating a production build
of a Next.js project using Color.js.

See this Github issue for an analysis of the bug:
#260

* Add comment for workaround
  • Loading branch information
lloydk authored Feb 11, 2024
1 parent 64780c3 commit 8b2d429
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/serialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@ export default function serialize (color, {
?? color.space.getFormat("default")
?? ColorSpace.DEFAULT_FORMAT;

inGamut ||= format.toGamut;
// The assignment to coords and inGamut needs to stay in the order they are now
// The order of the assignment was changed as a workaround for a bug in Next.js
// See this issue for details: https://github.com/color-js/color.js/issues/260

let coords = color.coords.slice(); // clone so we can manipulate it

inGamut ||= format.toGamut;

if (inGamut && !checkInGamut(color)) {
// FIXME what happens if the color contains NaNs?
coords = toGamut(clone(color), inGamut === true ? undefined : inGamut).coords;
Expand Down

0 comments on commit 8b2d429

Please sign in to comment.