Skip to content

remotion: Fix prefetch() cleanup for shared assets - #12591

Merged
JonnyBurger merged 1 commit into
mainfrom
fix/prefetch-shared-asset-cleanup
Oct 24, 2026
Merged

JonnyBurger merged 1 commit into
mainfrom
fix/prefetch-shared-asset-cleanup

Conversation

@JonnyBurger

@JonnyBurger JonnyBurger commented Oct 24, 2026 •

Copy link
Copy Markdown
Member

When two components prefetched the same asset, either component's free() removed the shared preload, causing the other component to fetch the original URL again despite having a completed prefetch.

Track completed prefetches by handle identity and keep the most recently completed live URL active. Freeing a handle releases only its own URL, restores another completed prefetch when needed, and becomes harmless when called again. This works for identical base64 URLs as well as blob URLs. Also release a blob URL if cancellation happens just before it is registered.

Document the independent cleanup behavior for 4.0.539.

Validation:

  • Red/green verified in native Chrome: a real image no longer re-fetches the original asset while another completed prefetch remains active.
  • Real React/public prefetch() checks passed for both cleanup orders, identical base64 URLs, mixed methods, reversed completion, repeated cleanup, hash aliases, cancellation, and failed sibling requests.
  • Verified each blob is revoked exactly once, including cancellation after creation but before registration.
  • All 725 core tests passed.
  • Full build, style checks, and docs preview-card generation passed.

Preview

@vercel

vercel Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
bugs Ready Ready Preview Oct 24, 2026 8:40am UTC
remotion Ready Ready Preview Oct 24, 2026 8:40am UTC

Request Review

@pullfrog pullfrog Bot 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.

✅ No new issues found.

Reviewed changes

  • Shared-prefetch registry — activePrefetches tracks completed prefetches per srcWithoutHash as a Map<symbol, string>, using a per-call prefetchId so two handles for the same asset no longer clobber each other.
  • Non-destructive cleanup — free() now deletes only its own entry, restores another completed URL into preloads when one remains, and drops the preload only when the last entry goes; the p[src] === remainingUrl short-circuit avoids needless re-renders.
  • Idempotent free() — the canceled guard moved to the top, making repeated free() calls harmless.
  • Cancellation blob revoke — a blob URL created after free() raced the completion path is revoked before registration instead of leaking.
  • Docs — prefetch.mdx free() wording fixed and the independent-cleanup behavior documented as <AvailableFrom v="4.0.539" inline />, matching the next patch above VERSION = '4.0.538'.

I traced the cleanup paths and found the bookkeeping consistent: for blob URLs each createObjectURL string is unique, so [...values()].pop() never restores an already-revoked URL; for base64 the values are identical strings and no revoke is performed, so the short-circuit is equivalent to a rewrite. Mixed base64/blob and reversed completion orders also restore a live URL owned by a still-active handle. bun test src/test/prefetch.test.ts passes on the branch.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash | 𝕏

@JonnyBurger
JonnyBurger merged commit c81a206 into main Oct 24, 2026
21 checks passed
@JonnyBurger
JonnyBurger deleted the fix/prefetch-shared-asset-cleanup branch October 24, 2026 08:46

This branch was successfully deployed

2 active deployments
Preview – remotion — ca6909a8 Deployed Oct 24, 2026 by vercel[bot]
Preview – bugs — ca6909a8 Deployed Oct 24, 2026 by vercel[bot]
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