Skip to content

[refractive] ImageData is not defined #8612

@Profesor08

Description

@Profesor08

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

  1. unzip
  2. npm install
  3. npm run dev
  4. open in browser
  5. 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.

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions