← Back to Pull requests

[vite-plugin v1 backport] Keep deferred imports alive after requests end #17082

Merged
petebacondarwin merged 3 files (221 lines) on Nov 21, 2026 22:15 UTC
View on GitHub
petebacondarwin petebacondarwin commented on Nov 20, 2026 14:03 UTC
Author

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.

---

  • Tests

  • - [x] Tests included/updated
    - [ ] Automated tests not possible - manual testing has been completed as follows:
    - [ ] Additional testing not necessary because:
  • Public documentation

  • - [ ] Cloudflare docs PR(s):
    - [x] Documentation not necessary because: restores existing local development behavior without a configuration change.

    [!NOTE]

    This is a contribution from an AI agent: Codex.

    Diff: 221 lines (+208 / -13) across 3 files Reviewer: NuroDev Review duration: 1932m
    All Vouch review confidence checks passed
    Residual risk 0.05 = Change Risk (0.38) × (1 − Review Confidence (0.87)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.38 · 221 lines diff across 3 files
    0.38
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.83 · 5 substantive comment(s)
    0.83
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    87%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.323
    Real PR Conversation Timeline
    12 items
    changeset-bot[bot] changeset-bot[bot] commented on Nov 20, 2026 14:03 UTC
    Bot

    🦋 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

    workers-devprod workers-devprod commented on Nov 20, 2026 14:03 UTC
    Contributor

    Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler
  • pkg-pr-new[bot] pkg-pr-new[bot] commented on Nov 20, 2026 14:04 UTC
    Bot

      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-ai-integration[bot] devin-ai-integration[bot] commented on code on Nov 20, 2026 14:04 UTC
    Code Review
    .changeset/v1-import-lifetime.md:1
    @@ -0,0 +1,7 @@
    +---
    +"@cloudflare/vite-plugin": patch
    +---
    +
    +Keep deferred imports alive after their originating request ends
    +
    +Retain the module runner's RPC operation until its result is retrieved and cleaned up. This prevents subsequent requests from hanging on a cached import when the first request returns early or its client disconnects.

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

    petebacondarwin petebacondarwin commented on Nov 20, 2026 14:04 UTC
    Author

    <!-- 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-ai-integration[bot] devin-ai-integration[bot] commented on Nov 20, 2026 14:04 UTC
    Reviewer

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

    ask-bonk[bot] ask-bonk[bot] commented on Nov 20, 2026 14:04 UTC
    Bot

    LGTM

    [github run](/cloudflare/workers-sdk/actions/runs/44749776875)

    clanky-the-clanker[bot] clanky-the-clanker[bot] commented on Nov 20, 2026 14:04 UTC
    Reviewer

    <!-- 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>

    NuroDev NuroDev approved these changes on Nov 20, 2026 14:43 UTC
    Approved Reviewer

    Approved these changes.

    workers-devprod workers-devprod approved these changes on Nov 20, 2026 14:44 UTC
    Approved Reviewer

    Codeowners reviews satisfied

    clanky-the-clanker[bot] clanky-the-clanker[bot] commented on Nov 21, 2026 12:35 UTC
    Reviewer

    <!-- 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>

    Reviewers
    Assignees
    petebacondarwin petebacondarwin
    Labels
    risk: low confidence: 87% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 38.2% (MEDIUM) · Higher = larger blast radius
    38.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 87% · Lower = rushed or shallow review
    87%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 5.0% · Safe to merge
    5.0%