Skip to content

fix(ssr)!: don't access Object variable in ssr transformed code #19996

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jun 9, 2025

Conversation

hi-ogawa
Copy link
Collaborator

@hi-ogawa hi-ogawa commented May 3, 2025

Description

I added __vite_ssr_exportName__ to runtime context so we can move out Object.definedProperty from ssr transformed code. Since this breaks vite-node, I added a patch to add the same runtime context. (EDIT: updated to vitest 3.2 beta)

This is likely hard to test on ecosystem ci since anyone using Vitest / vite-node breaks 🤔
I made a Vitest side PR (and package) so they can be tested if both overrides are setup vitest-dev/vitest#7925.

As seen in ecosystem-ci below, this change didn't break vite-plugin-cloudflare nor vite-environment-examples because their custom module runner uses Object.keys(context) and Object.values(context) without referencing exact context keys https://github.com/cloudflare/workers-sdk/blob/1cd30a554f00dfd7bff43bbd3e601bc67f7acb2b/packages/vite-plugin-cloudflare/src/runner-worker/module-runner.ts#L55-L69

hi-ogawa added 2 commits May 3, 2025 15:13

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
@hi-ogawa
Copy link
Collaborator Author

hi-ogawa commented May 3, 2025

/ecosystem-ci run

Copy link

pkg-pr-new bot commented May 3, 2025

Open in StackBlitz

npm i https://pkg.pr.new/vite@19996

commit: da582f8

@vite-ecosystem-ci
Copy link

📝 Ran ecosystem CI on 9ac01e3: Open

suite result latest scheduled
analogjs failure success
ladle failure success
nuxt failure success
laravel failure failure
quasar failure success
histoire failure success
storybook failure success
react-router ⏹️ cancelled success
sveltekit failure success
vike failure failure
unocss failure success
vite-plugin-svelte failure success
vite-plugin-react failure success
vite-plugin-vue failure success
vitepress failure success
waku failure success
vitest failure failure
vuepress failure success

astro, rakkas, previewjs, qwik, marko, vite-plugin-pwa, vite-plugin-react-swc, vite-environment-examples, vite-plugin-cloudflare, vite-setup-catalogue

@hi-ogawa hi-ogawa marked this pull request as ready for review May 3, 2025 08:47
@sapphi-red sapphi-red added this to the 7.0 milestone May 7, 2025
@sapphi-red sapphi-red added p3-minor-bug An edge case that only affects very specific usage (priority) feat: ssr breaking change labels May 7, 2025
Copy link
Member

@sapphi-red sapphi-red left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

sapphi-red
sapphi-red previously approved these changes May 7, 2025

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
hi-ogawa added 5 commits May 29, 2025 09:21

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
@sapphi-red

This comment was marked as resolved.

@vite-ecosystem-ci

This comment was marked as resolved.

@vite-ecosystem-ci

This comment was marked as outdated.

@vite-ecosystem-ci

This comment was marked as outdated.

@vite-ecosystem-ci
Copy link

📝 Ran ecosystem CI on 2a7473c: Open

suite result latest scheduled
nuxt success failure
react-router ⏹️ cancelled success
astro failure failure
analogjs failure failure
histoire failure failure
waku failure success
vitest failure success
vite-plugin-cloudflare failure failure
previewjs failure failure
vike failure failure

quasar, ladle, storybook, marko, qwik, vite-environment-examples, rakkas, vitepress, unocss, vite-plugin-react, vuepress, vite-plugin-vue, vite-setup-catalogue, vite-plugin-pwa, vite-plugin-svelte, sveltekit, laravel

@sapphi-red
Copy link
Member

I tried adding overrides (vitejs/vite-ecosystem-ci#387) but it seems it doesn't work for some and would make it difficult to understand the failures, so probably better to keep it as-is.

Verified

This commit was signed with the committer’s verified signature.
@sapphi-red
Copy link
Member

/ecosystem-ci run

@vite-ecosystem-ci
Copy link

📝 Ran ecosystem CI on da582f8: Open

suite result latest scheduled
ladle failure success
astro failure failure
analogjs failure failure
histoire failure failure
react-router ⏹️ cancelled success
quasar failure success
previewjs failure failure
laravel failure success
unocss failure success
vike failure failure
vite-plugin-cloudflare failure failure
waku failure success
vite-plugin-react failure success
vuepress failure success
vitepress failure success
sveltekit failure failure

marko, storybook, rakkas, qwik, nuxt, vite-plugin-pwa, vite-environment-examples, vite-plugin-vue, vite-setup-catalogue, vite-plugin-svelte, vitest

@hi-ogawa
Copy link
Collaborator Author

hi-ogawa commented Jun 6, 2025

Should I try to send PRs on ecosystem repos (at least the ones passing on the main)? Not sure how long renovate will get Vitest bumped.


I sent a message on discord in case it helps.

@sapphi-red
Copy link
Member

Thanks for sending the message 🙏 I hope some of the failures will be resolved next week, assuming the renovate will run once a week.

@sapphi-red
Copy link
Member

Ah, maybe adding "vitest@~3.0.0||~3.1.0>vite": "^6.3.5" to overrides might work

@hi-ogawa
Copy link
Collaborator Author

hi-ogawa commented Jun 6, 2025

Aha, that sounds great. Some frameworks like react-router uses vite-node, so that also needs override if you want to check.

I also noticed there's very old Vitest in the ecosystem "vitest": "^0.34.4" https://github.com/laravel/vite-plugin/blob/4a1c05598cc9fd14a26ceb9a125fee17fb828002/package.json#L53, which won't match vitest@~3.0.0||~3.1.0.

@sapphi-red
Copy link
Member

I've tested it at vitejs/vite-ecosystem-ci#389
It seems to work for most suites. But it didn't work with react-router.

@hi-ogawa
Copy link
Collaborator Author

hi-ogawa commented Jun 6, 2025

Just in case, I tested react router and overrides seems to be fine locally with:

    "overrides": {
      "vite": "https://pkg.pr.new/vite@da582f8",
      "vite-node": "3.2.2",

@sapphi-red

This comment was marked as outdated.

@vite-ecosystem-ci

This comment was marked as outdated.

@sapphi-red
Copy link
Member

/ecosystem-ci run

@vite-ecosystem-ci
Copy link

📝 Ran ecosystem CI on da582f8: Open

suite result latest scheduled
analogjs failure failure
histoire failure failure
astro failure failure
react-router failure success
vike failure failure
sveltekit failure failure
vite-plugin-cloudflare failure failure

ladle, laravel, marko, nuxt, quasar, qwik, storybook, vite-plugin-vue, vite-environment-examples, unocss, vite-plugin-svelte, vitest, rakkas, vite-plugin-react, waku, vuepress, vite-setup-catalogue, vite-plugin-pwa, vitepress

@sapphi-red
Copy link
Member

Let's now merge this PR as the ecosystem-ci is mostly passing.

@sapphi-red sapphi-red merged commit fceff60 into vitejs:main Jun 9, 2025
16 checks passed
sapphi-red added a commit to sapphi-red/vite that referenced this pull request Jun 9, 2025

Verified

This commit was signed with the committer’s verified signature.
@hi-ogawa hi-ogawa deleted the fix-ssr-object-var branch June 9, 2025 05:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change feat: ssr p3-minor-bug An edge case that only affects very specific usage (priority) trigger: preview
Projects
None yet
2 participants