[vite-plugin v1 backport] Keep deferred imports alive after requests end #17082
🦋 Changeset detected
Latest commit: 2bfb8940b37ec315c477730de2b5d7c3cadd2504
The changes in this PR will be included in the next version bump.
<details><summary>This PR includes changesets to release 1 package</summary>
| Name | Type |
| ----------------------- | ----- |
| @cloudflare/vite-plugin | Patch |
</details>
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
Codeowners approval required for this PR:
npm i https://pkg.pr.new/@cloudflare/vite-plugin@17082
_commit: <a href="https://github.com/cloudflare/workers-sdk/runs/136847489156"><code>2bfb894</code></a>_
<!-- devin-review-comment {"id": "ANALYSIS_pr-review-job-733680046b9e4e0f939a4896c4274127_0001", "file_path": ".changeset/v1-import-lifetime.md", "start_line": 7, "end_line": 7, "side": "RIGHT", "kind": "analysis"} -->
🔍 Implementation details in user-facing changeset
The changeset includes RPC retention and cleanup details, contrary to the changeset guidance. The subsequent-request hang already explains the user-facing benefit.
<!-- devin-review-badge-begin -->
<a href="https://cloudflare.devinenterprise.com/review/cloudflare/workers-sdk/pull/17082" target="_blank"><picture><source media="(prefers-color-scheme: dark)" srcset="https://static.devin.ai/assets/gh-devin-review-dark.svg?v=4"><img src="https://static.devin.ai/assets/gh-devin-review-light.svg?v=4" alt="Devin Review"></picture></a>
<!-- devin-review-badge-end -->
---
Was this helpful? React with 👍 or 👎 to provide feedback.
<!-- vite-plugin-v1-backport-review-request:original=16385 -->
@aryasaatvik @petebacondarwin, please check this v1 backport of #16385 and approve if it looks good. You are the verified original author and latest qualifying human ant-core approver before merge (deduplicated where applicable).
The module-runner implementation is unchanged. The original three integration cases use equivalent v1 Wrangler configuration and omit the v2 runtime-types option. They fail before and pass after the fix; build, types, checks and package tests pass. This does not require the unpublished runtime increment in #17054.
Devin Review found 1 potential issue.
<!-- devin-review-badge-begin -->
<a href="https://cloudflare.devinenterprise.com/review/cloudflare/workers-sdk/pull/17082" target="_blank"><picture><source media="(prefers-color-scheme: dark)" srcset="https://static.devin.ai/assets/gh-devin-review-dark.svg?v=4"><img src="https://static.devin.ai/assets/gh-devin-review-light.svg?v=4" alt="Devin Review"></picture></a>
<!-- devin-review-badge-end -->
LGTM
[github run](/cloudflare/workers-sdk/actions/runs/44749776875)
<!-- durable-reviewer:review run=9bb9a6dc-a3c8-4ab2-9133-6264356eaef9 -->
Superseded by the review of 2bfb8940.<details>
<summary>This review, of <code>d78ce017</code></summary>
✅ Approved — A small backport with regression tests. Wrapping the RPC operation in waitUntil() is correct and keeps the errors callers see unchanged; no issues found.
<sub>The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.</sub>
---
<details>
<summary>✅ All checks passed</summary>
🚀 Release: ✅ LGTM
Overall risk: Low. A focused fix to the module runner's RPC lifetime (module-runner.ts:42-63), with integration regression coverage and a patch changeset.
---
🔒 Security: ✅ LGTM
No issues found.
---
📖 AGENTS.md: ✅ LGTM
No issues found.
---
📋 Code Quality: ✅ LGTM
No issues found.
---
⚡ Performance: ✅ LGTM
No issues found.
---
📝 Documentation: ✅ LGTM
No issues found.
</details>
---
<sub>Reviewed commit: d78ce017</sub>
</details>
Approved these changes.
Codeowners reviews satisfied
<!-- durable-reviewer:review run=44ecb49a-3482-45e3-9195-419371b7ab7d -->
✅ Approved — This is a small backport with regression tests. Wrapping the RPC operation in waitUntil() is correct, and the Windows-only test setup added since the last review is sound. No issues found.
<sub>The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.</sub>
---
<details>
<summary>✅ All checks passed</summary>
🚀 Release: ✅ LGTM
Overall risk: Low. This is a focused fix to how long the module runner's RPC operation stays alive. It includes integration regression tests and a patch changeset.
---
🔒 Security: ✅ LGTM
No issues found.
---
📖 AGENTS.md: ✅ LGTM
No issues found.
---
📋 Code Quality: ✅ LGTM
The module-runner.ts change hasn't changed since the last review. It wraps the RPC operation in waitUntil() and returns the same promise, so callers still see the same results and errors.
The only new change is the Windows-only beforeEach in import-lifetime.spec.ts. It calls realpath on the temp directory, changes into it, and stubs PWD to match. afterEach calls vi.unstubAllEnvs() to undo the stub. This looks correct.
---
⚡ Performance: ✅ LGTM
No issues found.
---
📝 Documentation: ✅ LGTM
No issues found.
</details>
---
<sub>Reviewed commit: 2bfb8940</sub>
NuroDev
petebacondarwin
Backports #16385 to prevent deferred dynamic imports from losing their caller RPC continuation when a request returns or disconnects. The runner implementation and changeset are unchanged from the original. The complete RPC operation, result retrieval and cleanup are retained through waitUntil().
The three original integration regressions are retained. The only v1 adaptations are writing the equivalent wrangler.json instead of cloudflare.config.ts, and omitting the v2 runtime-types option. The explicit import gate, separate evaluation/settlement observations and direct workerd disconnect case are unchanged, including the Windows skip. All three fail before the fix (v1 reports an ended-request promise rather than returning the cached value/rejection) and pass after it.
Validation: pnpm build, pnpm check (58 tasks, including types/lint/format), and pnpm test:ci (8 tasks, 271 plugin tests) pass on the current v1 target with published dependencies. No dependency changes or public sibling source are included. #17054's unpublished runtime increment follows the validated backports in native GitHub stack #17084 rooted at vite-plugin-v1.
---
- [x] Tests included/updated
- [ ] Automated tests not possible - manual testing has been completed as follows:
- [ ] Additional testing not necessary because:
- [ ] Cloudflare docs PR(s):
- [x] Documentation not necessary because: restores existing local development behavior without a configuration change.