solidjs-community / solidjs-community/solid-primitives
`resize-observer@4.0.0-next.3` causes hydration mismatch
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 1.6k
- Forks
- 162
- Avg merge
- 19h 40m
- Merged PRs (30d)
- 8
Description
Describe the bug
import { createSignal } from "solid-js";
import { createElementSize } from "@solid-primitives/resize-observer";
export default function ElementSizeHydrationRepro() {
const [target, setTarget] = createSignal<HTMLDivElement>();
const size = createElementSize(target);
return <><div ref={setTarget}>Width: </div>{size.width ?? "waiting"}</>;
}
The cause is that createEffect advances hydration id but it's only created on the client:
A workaround would be wrapping the use site in a new owner. A proper fix would be always createEffect regardless of isServer or not.
BTW, I believe that the idiomatic Solid2 way of writing this would be creating a writable signal with ssrSource: "client". This way the returned size can be non-null, but the result must be wrapped in a separate <Loading> boundary or else the component could never render due to the loop render -> get size -> observed el not mounted until rendered -> isPending, abort render. It sounds problematic at first but it actually prevents the render loop of using the size inside the measured element. However, that's a behavior change and needs discussion.
Minimal Reproduction Link
stack blitz pnpm is too old to run the new template
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in packages/resize-observer/src/index.ts around line 201, where createEffect is gated by isServer. Compare server and client hydration behavior using the provided ElementSizeHydrationRepro component. Done means the resize observer no longer causes a hydration mismatch while preserving the intended size behavior; the Solid2 behavior discussion may require separate clarification.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100