Skip to content

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

Merged
sapphi-red merged 9 commits intovitejs:mainfrom
hi-ogawa:fix-ssr-object-var
Jun 9, 2025
Merged

fix(ssr)!: don't access Object variable in ssr transformed code#19996
sapphi-red merged 9 commits intovitejs:mainfrom
hi-ogawa:fix-ssr-object-var

Conversation

@hi-ogawa
Copy link
Copy Markdown
Contributor

@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

Loading
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

Development

Successfully merging this pull request may close these issues.

Live binding does not work when the Object constructor is shadowed Exporting redefined "Object" throws an error in SSR

2 participants