Describe the bug
This error occurs because @hashintel/refractive relies on the browser's Canvas API (specifically the ImageData constructor), which does not exist in the Node.js environment where Next.js performs Server-Side Rendering (SSR).
The library is trying to calculate a displacement map or rounded square map during the initial server-side render, but ImageData is a Web API only available in actual browsers.
Runtime Error
ImageData is not defined
Call Stack
node_modules\@hashintel\refractive\src\maps\calculate-rounded-square-map.ts (74:21)
node_modules\@hashintel\refractive\src\maps\displacement-map.ts (72:10)
node_modules\@hashintel\refractive\src\components\filter.tsx (81:27)
|
const imageData = new ImageData(width, height); |
To reproduce
refractive-ssr-bug.zip
- unzip
npm install
npm run dev
- open in browser
- see error in dev panel and in terminal
Expected behavior
No errors
Device
No response
Operating system
Windows 11
Browser
Chrome latest
Additional context
I think, computation of svg filter should happen on client side, inside useEffect. This will move all logic to client, and will not do any work on server side. Also, computations produce massive images (200kb+), and computing a few, on server side, will blow up html size.
Describe the bug
This error occurs because
@hashintel/refractiverelies on the browser's Canvas API (specifically theImageDataconstructor), which does not exist in the Node.js environment where Next.js performs Server-Side Rendering (SSR).The library is trying to calculate a displacement map or rounded square map during the initial server-side render, but
ImageDatais a Web API only available in actual browsers.hash/libs/@hashintel/refractive/src/maps/calculate-rounded-square-map.ts
Line 74 in b03f6fe
To reproduce
refractive-ssr-bug.zip
npm installnpm run devExpected behavior
No errors
Device
No response
Operating system
Windows 11
Browser
Chrome latest
Additional context
I think, computation of svg filter should happen on client side, inside
useEffect. This will move all logic to client, and will not do any work on server side. Also, computations produce massive images (200kb+), and computing a few, on server side, will blow up html size.