cssinjs / cssinjs/jss

React strict mode forces dynamic rules to be added twice which breaks hydration

Open
#1,643 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
7.1k
Forks
386
PR merge metrics
No merged PRs in 30d

Description

__Expected behavior:__
Consistent jssId and ruleCounter with strict mode

__Describe the bug:__
Using React Strict Mode wrapper forces dynamic rules to be generated twice on client. On next js server they are generated only one time. This all leads to classes mismatch by counter at some point

__Reproduction:__

https://codesandbox.io/p/sandbox/upbeat-grothendieck-9ne4d2
Look how input, text and container classes in dom are 1 step behind from generated on client stylesheets with strict mode enabled

__Versions (please complete the following information):__
- jss: 10.10.0
- Browser [e.g. chrome, safari]: Chrome
- OS [e.g. Windows, macOS]: macOs
- React: 18.2.0

Contributor guide

Open the contributing guide

Research direction

Start with the linked CodeSandbox reproduction using JSS 10.10.0, React 18.2.0, and Next.js, then compare the server- and client-generated styles under React Strict Mode. Trace where dynamic rules, jssId, and ruleCounter are created. Done means hydration produces matching classes and styles without duplicate rule generation.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, next.js, react
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.