Skip to content

fix(vite-dev-server): wait for support file and retry dynamic imports to avoid CI race#33487

Draft
mschile wants to merge 4 commits intodevelopfrom
mschile/vite_failed_dynamic_import
Draft

fix(vite-dev-server): wait for support file and retry dynamic imports to avoid CI race#33487
mschile wants to merge 4 commits intodevelopfrom
mschile/vite_failed_dynamic_import

Conversation

@mschile
Copy link
Copy Markdown
Contributor

@mschile mschile commented Mar 17, 2026

  • Closes

Additional details

  • Why: In CI (and sometimes locally), the Cypress iframe can load and run initCypressTests.js before the Vite dev server has finished serving the support file or spec module, leading to "Failed to fetch dynamically imported module" and flaky failures.
  • What's affected: @cypress/vite-dev-server startup and the client-side dynamic imports in the test iframe (support file + spec).
  • Implementation: (1) Server: After server.listen(), we now wait until the support file URL returns HTTP 200 (waitUntilUrlReady) so "dev server ready" is deterministic. New waitForSupportFile.ts builds the same URL path the client uses and polls until 2xx. (2) Client: Dynamic imports for the support file and spec(s) are wrapped in retryDynamicImport() (up to 4 attempts, 400ms apart) for retryable errors (e.g. "Failed to fetch", "dynamically imported module", "Importing a module script failed").

Steps to test

  • Run component tests (or system tests that use the Vite dev server) in an environment where the server can be slow to serve modules (e.g. CI or under load). Before: occasional "Failed to fetch dynamically imported module"; after: server waits for support file and client retries imports.
  • New unit tests: yarn workspace @cypress/vite-dev-server test -- waitForSupportFile.spec.ts

How has the user experience changed?

  • Before: Intermittent failures when the iframe requested the support/spec module before Vite had it ready.
  • After: Dev server is considered ready only when the support file is servable, and the client retries transient import failures, reducing flakiness.

PR Tasks

@cypress
Copy link
Copy Markdown

cypress bot commented Mar 18, 2026

cypress    Run #69435

Run Properties:  status check passed Passed #69435  •  git commit 4efbba5f0a: updates
Project cypress
Branch Review mschile/vite_failed_dynamic_import
Run status status check passed Passed #69435
Run duration 08m 48s
Commit git commit 4efbba5f0a: updates
Committer Matthew Schile
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 1
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 739
View all changes introduced in this branch ↗︎

Warning

No Report: Something went wrong and we could not generate a report for the Application Quality products.

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