Skip to content

Conversation

@jennifer-shehane
Copy link
Member

@jennifer-shehane jennifer-shehane commented Dec 17, 2025

Additional details

Component tests were experiencing intermittent failures with TypeError: Failed to fetch dynamically imported module when loading the support file. This occurred due to a race condition where the dynamic import executed before Vite's optimizeDeps finished processing the module.

Vite's optimizeDeps runs asynchronously in the background. Even though the support file is added to optimizeDeps.entries for pre-bundling, server.listen() can complete before the module is ready, causing the dynamic import to fail. Vite doesn't provide an API to wait for optimizeDeps completion.

Implemented retry logic with exponential backoff (3 attempts: 50ms, 100ms, 200ms) for support file imports. The implementation:

Vite's vite:preloadError event is designed for production version skew scenarios and doesn't help with dev server timing issues. Since there's no API to wait for optimizeDeps, retry logic is the most practical solution for this race condition.


Note

Listen for Vite preload errors when importing the support file, reload once to refresh assets with a sessionStorage loop guard, add targeted tests, and disable screenshots-on-failure in test fixtures.

  • Vite Dev Server (client):
    • Add vite:preloadError listener in npm/vite-dev-server/client/initCypressTests.js to detect failed dynamic imports of the support file.
    • Extract URL from Error.message when needed; on match with support file, preventDefault, set session flag (sessionStorage) to avoid reload loops, and window.location.reload().
    • Simplify support file loader to a direct import(relativeUrl).
  • Tests:
    • Extend npm/vite-dev-server/test/initCypressTests.spec.ts to validate listener registration, URL extraction, reload/guard behavior, and absence of retry logic; update window/sessionStorage mocks.
  • System Tests/Snapshots:
    • Update snapshots in system-tests/__snapshots__/vite_dev_server_fresh_spec.ts.js to reflect no screenshots on failures.
  • Config (fixtures):
    • Set screenshotOnRunFailure: false in system-tests/project-fixtures/react/cypress-vite.config.ts.

Written by Cursor Bugbot for commit 230dc8a. This will update automatically on new commits. Configure here.

Steps to test

How has the user experience changed?

PR Tasks

@jennifer-shehane jennifer-shehane self-assigned this Dec 17, 2025
@cypress
Copy link

cypress bot commented Dec 17, 2025

cypress    Run #68158

Run Properties:  status check passed Passed #68158  •  git commit 230dc8a80b: fix test
Project cypress
Branch Review vite-dev-server-retry-loading-support
Run status status check passed Passed #68158
Run duration 20m 56s
Commit git commit 230dc8a80b: fix test
Committer Jennifer Shehane
View all properties for this run ↗︎

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

Warning

Partial Report: The results for the Application Quality reports may be incomplete.

UI Coverage  45.18%
  Untested elements 194  
  Tested elements 164  
Accessibility  97.94%
  Failed rules  4 critical   8 serious   3 moderate   2 minor
  Failed elements 102  

@AtofStryker AtofStryker self-assigned this Dec 19, 2025
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.

Component tests failing intermittently with uncaught Vite "failed to fetch dynamically imported module" error in CI

3 participants