Skip to content

Stop the draft attachment snapshot test leaning on a leaked rAF - #910

Merged
wass08 merged 1 commit into
mainfrom
fix/draft-attachment-snapshot-raf
Sep 22, 2026
Merged

wass08 merged 1 commit into
mainfrom
fix/draft-attachment-snapshot-raf

Conversation

@wass08

@wass08 wass08 commented Sep 22, 2026 •

Copy link
Copy Markdown
Collaborator

draft-attachment-snapshot.test.ts fails with a bare ReferenceError: requestAnimationFrame is not defined depending on the order bun happens to run the core test files in. It surfaced on a private-editor CI run, on a diff that touched nothing in the editor.

Cause

updateNode batches its dirty-node flush through requestAnimationFrame (store/actions/node-actions.ts:1465), which bun's test runtime has no DOM to supply. Seven other core tests that reach this path stub the global themselves — use-scene-dirty-tracking, node-update-children, wall-merge, host-children, procedural-persistence, procedural-items/mutations, use-scene-temporal-reconciliation. This one never did, so it passed only when one of those ran first and leaked globalThis.requestAnimationFrame behind it. Run the file on its own and it fails every time, on main as much as anywhere:

bun test src/store/draft-attachment-snapshot.test.ts
ReferenceError: requestAnimationFrame is not defined
  at updateNodesActionImpl (src/store/actions/node-actions.ts:1465:18)

Fix

Stub rAF for the duration of the test and restore it in the finally that's already there, matching the idiom in the neighbouring store tests.

Testing

  • bun test src/store/draft-attachment-snapshot.test.ts on its own: passes (failed before).
  • bun test src in packages/core: 2865 pass, 0 fail.
  • Audited every core test that calls updateNode/updateNodes without stubbing rAF — registry/scene-api.test.ts is the only other one, and it passes standalone because it doesn't reach the batched path. No further latent cases.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Jmmz2AMwTzcnKsSHHPEMhN


Note

Low Risk
Test-only change with no production code or runtime behavior impact.

Overview
Fixes order-dependent flakiness in draft-attachment-snapshot.test.ts: the test calls updateNode, which schedules a dirty-node flush via requestAnimationFrame, but Bun’s test environment has no DOM globals.

The test now stubs globalThis.requestAnimationFrame and cancelAnimationFrame for the duration of the scenario and restores the originals in the existing finally block, matching other core store tests. It no longer relies on another test file having run first and leaked a stub onto globalThis.

Reviewed by Cursor Bugbot for commit 07e0251. Bugbot is set up for automated code reviews on this repo. Configure here.

`updateNode` batches its dirty-node flush through `requestAnimationFrame`,
which bun's test runtime has no DOM to supply. Seven other core tests that
reach this path stub it; this one did not, and passed only when bun
happened to run one of them first and leak the global. On a runner that
ordered the files differently it failed with a bare ReferenceError, and
running the file on its own failed every time.

Stubs rAF for the duration of the test and restores it in the existing
finally, matching how the neighbouring store tests do it.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Jmmz2AMwTzcnKsSHHPEMhN
@pascal

pascal Bot commented Sep 22, 2026

Copy link
Copy Markdown

I hit an error while handling your request (Model unavailable on AI Gateway free tier: Free tier users do not have access to this model. Upgrade to paid credits at https://vercel.com/d?to=%2F%5Bteam%5D%2F%7E%2Fai%3Fmodal%3Dtop-up for unrestricted…).

Please try again, rephrase, or reach out if it keeps failing.

Error id: a4b5a434-b9a1-4be7-a90b-7d777d724d89

@wass08
wass08 merged commit fc3afde into main Sep 22, 2026
4 checks passed
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.

1 participant