Skip to content

Fix "Cannot perform I/O on behalf of a different request" errors for deferred dynamic imports#12953

Merged
jamesopstad merged 2 commits intomainfrom
james/request-context-errors
Mar 26, 2026
Merged

Fix "Cannot perform I/O on behalf of a different request" errors for deferred dynamic imports#12953
jamesopstad merged 2 commits intomainfrom
james/request-context-errors

Conversation

@jamesopstad
Copy link
Copy Markdown
Contributor

@jamesopstad jamesopstad commented Mar 18, 2026

Fixes #12731.

Fix Cannot perform I/O on behalf of a different request errors for deferred dynamic imports

Concurrent requests that loaded the same dynamic import were previously sharing the same promise to resolve it in a Worker context. We now ensure that all imports execute within a Durable Object's IoContext before the result is returned to the Worker.

This PR also revises and improves the module runner implementation more generally. We now only use public Vite APIs.


  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows: tested with overlapping HMR updates and browser requests in Waku, TanStack Start and React Router.
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: bug fix

A picture of a cute animal (not mandatory, but encouraged)


Open with Devin

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 18, 2026

🦋 Changeset detected

Latest commit: 3a001b3

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-project-automation github-project-automation bot moved this to Untriaged in workers-sdk Mar 18, 2026
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 18, 2026

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@12953

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@12953

miniflare

npm i https://pkg.pr.new/miniflare@12953

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@12953

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@12953

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@12953

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@12953

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@12953

wrangler

npm i https://pkg.pr.new/wrangler@12953

commit: 3a001b3

@jamesopstad jamesopstad force-pushed the james/request-context-errors branch from 706167c to a7dedab Compare March 25, 2026 08:23
@jamesopstad jamesopstad force-pushed the james/request-context-errors branch from a7dedab to 3a001b3 Compare March 26, 2026 10:29
@github-actions
Copy link
Copy Markdown
Contributor

✅ All changesets look good

@jamesopstad jamesopstad changed the title New module runner implementation Fix "Cannot perform I/O on behalf of a different request" errors for deferred dynamic imports Mar 26, 2026
@jamesopstad jamesopstad marked this pull request as ready for review March 26, 2026 11:52
@jamesopstad jamesopstad requested a review from a team as a code owner March 26, 2026 11:52
@jamesopstad jamesopstad requested a review from ascorbic March 26, 2026 11:52
@workers-devprod
Copy link
Copy Markdown
Contributor

workers-devprod commented Mar 26, 2026

Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler
Show detailed file reviewers

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 5 additional findings.

Open in Devin Review

@github-project-automation github-project-automation bot moved this from Untriaged to Approved in workers-sdk Mar 26, 2026
@penalosa
Copy link
Copy Markdown
Contributor

I'm not super familiar with the internals of Vite's module runner, so this should probably also get a review from someone else more familiar with Vite. However, this is the same fix as Vitest needs, and that bit seems accurate to what I'd expect, so approving from that perspective.

@jamesopstad jamesopstad merged commit 80b093e into main Mar 26, 2026
56 of 63 checks passed
@jamesopstad jamesopstad deleted the james/request-context-errors branch March 26, 2026 17:10
@github-project-automation github-project-automation bot moved this from Approved to Done in workers-sdk Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Vite hot reload with bindings causes "promise was resolved or rejected from a different request context"

3 participants