Skip to content

Conversation

@hi-ogawa
Copy link
Contributor

@hi-ogawa hi-ogawa commented Apr 2, 2025

Description

Fixes https://discord.com/channels/917386801235247114/1356658374317445311
Fixes #7784

The following code (introduced in #7605) fails when transform is called before full server initialization (e.g. configureServer(server) { server.ssrLoadModule } like sveltekit https://github.com/sveltejs/kit/blob/f4ce1856ad9ea446c424bd818b25ae89e34a0692/packages/kit/src/exports/vite/dev/index.js#L400).

const browser = await createBrowserServer({
  ...
  filter() {
    // Cannot access 'browser' before initialization
    id.includes(browser.vite.config.cacheDir))
  }
})

I changed this to obtain cacheDir through a separate configResolved hook, which should be guaranteed to be defined earlier.

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

@netlify
Copy link

netlify bot commented Apr 2, 2025

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit be731c1
🔍 Latest deploy log https://app.netlify.com/sites/vitest-dev/deploys/67ec95758957740008415261
😎 Deploy Preview https://deploy-preview-7783--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Apr 2, 2025

@vitest/browser

npm i https://pkg.pr.new/@vitest/browser@7783

@vitest/coverage-istanbul

npm i https://pkg.pr.new/@vitest/coverage-istanbul@7783

@vitest/coverage-v8

npm i https://pkg.pr.new/@vitest/coverage-v8@7783

@vitest/expect

npm i https://pkg.pr.new/@vitest/expect@7783

@vitest/mocker

npm i https://pkg.pr.new/@vitest/mocker@7783

@vitest/pretty-format

npm i https://pkg.pr.new/@vitest/pretty-format@7783

@vitest/runner

npm i https://pkg.pr.new/@vitest/runner@7783

@vitest/snapshot

npm i https://pkg.pr.new/@vitest/snapshot@7783

@vitest/spy

npm i https://pkg.pr.new/@vitest/spy@7783

@vitest/ui

npm i https://pkg.pr.new/@vitest/ui@7783

@vitest/utils

npm i https://pkg.pr.new/@vitest/utils@7783

vite-node

npm i https://pkg.pr.new/vite-node@7783

vitest

npm i https://pkg.pr.new/vitest@7783

@vitest/web-worker

npm i https://pkg.pr.new/@vitest/web-worker@7783

@vitest/ws-client

npm i https://pkg.pr.new/@vitest/ws-client@7783

commit: 296ce0c

@hi-ogawa hi-ogawa changed the title fix(browser): fix transform before browser server initialization fix(browser): fix transform error before browser server initialization Apr 2, 2025
@hi-ogawa hi-ogawa marked this pull request as ready for review April 2, 2025 02:01
@JReinhold
Copy link

I have confirmed with the pkg.pr.new releases that it fixes the situation in Storybook. 🎉

@sheremet-va sheremet-va merged commit 5f762ec into vitest-dev:main Apr 2, 2025
13 of 14 checks passed
@hi-ogawa hi-ogawa deleted the fix-browser-init branch April 2, 2025 23:48
schogges pushed a commit to kumahq/kuma-gui that referenced this pull request Apr 23, 2025
v3.1.2
   🐞 Bug Fixes
Add global chai variable in vitest/globals (fix: #7474)  -  by @​Jay-Karia in vitest-dev/vitest#7771 and vitest-dev/vitest#7474 (d9297)
Prevent modifying test.exclude when same object passed in coverage.exclude  -  by @​AriPerkkio in vitest-dev/vitest#7774 (c3751)
Fix already hoisted mock  -  by @​hi-ogawa in vitest-dev/vitest#7815 (773b1)
Fix test.scoped inheritance  -  by @​hi-ogawa in vitest-dev/vitest#7814 (db6c3)
Remove pointer-events-none after resizing the left panel  -  by @​alexprudhomme in vitest-dev/vitest#7811 (a7e77)
Default to run mode when stdin is not a TTY  -  by @​kentonv, @​hi-ogawa and @​sheremet-va in vitest-dev/vitest#7673 (6358f)
Use happy-dom/jsdom types for envionmentOptions  -  by @​hi-ogawa in vitest-dev/vitest#7795 (67430)
browser:
Fix transform error before browser server initialization  -  by @​hi-ogawa in vitest-dev/vitest#7783 (5f762)
Fix mocking from outside of root  -  by @​hi-ogawa in vitest-dev/vitest#7789 (03f55)
Scale iframe for non ui case  -  by @​hi-ogawa in vitest-dev/vitest#6512 (c3374)
coverage:
await profiler calls  -  by @​AriPerkkio in vitest-dev/vitest#7763 (795a6)
Expose profiling timers  -  by @​AriPerkkio in vitest-dev/vitest#7820 (5652b)
deps:
Update all non-major dependencies  -  in vitest-dev/vitest#7765 (7c3df)
Update all non-major dependencies  -  in vitest-dev/vitest#7831 (15701)
runner:
Correctly call test hooks and teardown functions  -  by @​sheremet-va in vitest-dev/vitest#7775 (3c00c)
Show stacktrace on test timeout error  -  by @​hi-ogawa in vitest-dev/vitest#7799 (df33b)
ui:
Load panel sizes from storage on initial load  -  by @​userquin in vitest-dev/vitest#7265 (6555d)
vite-node:
Named export should overwrite export all  -  by @​hi-ogawa in vitest-dev/vitest#7846 (5ba0d)
Add ERR_MODULE_NOT_FOUND code error if module cannot be loaded  -  by @​sheremet-va in vitest-dev/vitest#7776 (f9eac)
   🏎 Performance
browser: Improve browser parallelisation  -  by @​sheremet-va in vitest-dev/vitest#7665 (816a5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot access 'browser' before initialization

3 participants