vite icon indicating copy to clipboard operation
vite copied to clipboard

fix(ssr): `this` in exported function should be `undefined`

Open sapphi-red opened this issue 1 year ago • 8 comments

Description

this in exported function should be undefined but it was not. reproduction in Node: https://stackblitz.com/edit/node-7bhlmx?file=index.js (make sure you run it locally, it works differently in stackblitz https://github.com/stackblitz/webcontainer-core/issues/1532)

I used an identity function to avoid the this binding. (0, foo.bar) can be used as well, but I thought it will be difficult for the same reason with https://github.com/vitejs/vite/pull/3682.

sapphi-red avatar Oct 11 '24 06:10 sapphi-red

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

/ecosystem-ci run

patak-dev avatar Oct 11 '24 07:10 patak-dev

📝 Ran ecosystem CI on 8549d55: Open

suite result latest scheduled
redwoodjs :x: failure :white_check_mark: success
remix :x: failure :x: failure
sveltekit :x: failure :x: failure
vike :x: failure :x: failure
vite-environment-examples :x: failure :white_check_mark: success
vitest :x: failure :white_check_mark: success

:white_check_mark: analogjs, astro, histoire, ladle, laravel, marko, nuxt, previewjs, quasar, qwik, rakkas, storybook, unocss, vite-plugin-pwa, vite-plugin-react, vite-plugin-react-swc, vite-plugin-svelte, vite-plugin-vue, vite-setup-catalogue, vitepress, vuepress

vite-ecosystem-ci[bot] avatar Oct 11 '24 07:10 vite-ecosystem-ci[bot]

/ecosystem-ci run

sapphi-red avatar Oct 11 '24 08:10 sapphi-red

vite-environment-examples and vitest are failing with snapshot diff caused by stacktrace change (Module.foo is now foo) or the output change which is expected. redwoodjs fail should be fixed by the last commit.

sapphi-red avatar Oct 11 '24 08:10 sapphi-red

📝 Ran ecosystem CI on 17be758: Open

suite result latest scheduled
remix :x: failure :x: failure
sveltekit :x: failure :x: failure
vike :x: failure :x: failure
vite-environment-examples :x: failure :white_check_mark: success
vitest :x: failure :white_check_mark: success

:white_check_mark: analogjs, astro, histoire, ladle, laravel, marko, nuxt, previewjs, quasar, qwik, rakkas, redwoodjs, storybook, unocss, vite-plugin-pwa, vite-plugin-react, vite-plugin-react-swc, vite-plugin-svelte, vite-plugin-vue, vite-setup-catalogue, vitepress, vuepress

vite-ecosystem-ci[bot] avatar Oct 11 '24 08:10 vite-ecosystem-ci[bot]

This change makes sense, but it might be affecting Vitest coverage a bit. Other than stacktrace, I found one coverage test is failing when testing with a local build. It's only one test case with Vue (specifically this one pnpm -C test/coverage-test test /vue.test -- --project v8), so it might be an issue in different parts though. I'll check with the team.

hi-ogawa avatar Oct 12 '24 04:10 hi-ogawa

@AriPerkkio What do you mean by left on source map? Is it the mapping from __vite_ssr_identity__( to the space on the original source in this example with sourcemap visualizer? If so, it is not intentional. That said, I don't know how to do that in a performant way, I think we need to improve magic-string to achieve that.

sapphi-red avatar Oct 12 '24 14:10 sapphi-red