fix: address canvas getting 0x0 on React strict mode - #444
Merged
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
The ref lifecycle fix is correctly scoped, preserves real cleanup, and has focused regression coverage.
Pull request overview
Prevents React 19 Strict Mode’s temporary ref detachment from clearing a live canvas while preserving backing-store cleanup on actual unmount.
Changes:
- Defers canvas cleanup and verifies the detached canvas was not reattached.
- Adds regression coverage for unmounting and immediate reattachment.
- Upgrades Rive runtimes to 2.42.1.
File summaries
| File | Description |
|---|---|
src/hooks/useRive.tsx |
Makes canvas cleanup Strict Mode-safe. |
test/useRive.test.tsx |
Tests deferred cleanup and reattachment. |
package.json |
Upgrades runtime dependencies. |
package-lock.json |
Locks upgraded runtime packages. |
Review details
- Files reviewed: 3/4 changed files
- Comments generated: 0
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Under React 19's Strict Mode, our previous change to actually set width/height 0x0 to the canvas on canvas unmount had a side effect. In strict mode, setCanvasRef gets an extra detach/reattach during mount, and that fake detach gets the 0x0 treatment. So when the element actually mounts, it's possible the canvas has 0x0. This fixes that behavior so we compare the prev/incoming canvas and if they're the same, we ignore the zero-out — if they differ, the old canvas really is gone and still gets released. The queueMicrotask defers the comparison to when a reattach should happen.
Also bumps the JS runtime to 2.42.1.
Addresses this comment from #440: #440 (comment)