Skip to content

fix: address canvas getting 0x0 on React strict mode - #444

Merged
zplata merged 1 commit into
mainfrom
react/440-followup-2
Sep 11, 2026
Merged

fix: address canvas getting 0x0 on React strict mode#444
zplata merged 1 commit into
mainfrom
react/440-followup-2

Conversation

@zplata

@zplata zplata commented Sep 11, 2026

Copy link
Copy Markdown
Collaborator

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)

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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.

@zplata
zplata requested a review from bodymovin September 11, 2026 20:38

@bodymovin bodymovin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zplata
zplata merged commit 094a142 into main Sep 11, 2026
2 checks passed
@zplata
zplata deleted the react/440-followup-2 branch September 11, 2026 21:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants