Skip to content

Commit a17da55

Browse files
authored
fix: check exactly in proxyESM (#5512)
1 parent 87c0050 commit a17da55

File tree

5 files changed

+39
-2
lines changed

5 files changed

+39
-2
lines changed

packages/playground/ssr-vue/__tests__/ssr-vue.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ import fetch from 'node-fetch'
44

55
const url = `http://localhost:${port}`
66

7+
test('vuex can be import succeed by named import', async () => {
8+
await page.goto(url + '/store')
9+
expect(await page.textContent('h1')).toMatch('bar')
10+
11+
// raw http request
12+
const storeHtml = await (await fetch(url + '/store')).text()
13+
expect(storeHtml).toMatch('bar')
14+
})
15+
16+
717
test('/about', async () => {
818
await page.goto(url + '/about')
919
expect(await page.textContent('h1')).toMatch('About')

packages/playground/ssr-vue/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"dependencies": {
1717
"example-external-component": "file:example-external-component",
1818
"vue": "^3.2.21",
19-
"vue-router": "^4.0.0"
19+
"vue-router": "^4.0.0",
20+
"vuex": "^4.0.2"
2021
},
2122
"devDependencies": {
2223
"@vitejs/plugin-vue": "workspace:*",
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<template>
2+
<h1>{{ foo }}</h1>
3+
</template>
4+
5+
<script>
6+
import { createStore } from 'vuex'
7+
8+
export default {
9+
async setup() {
10+
const store = createStore({
11+
state: {
12+
foo: 'bar'
13+
}
14+
})
15+
return store.state
16+
}
17+
}
18+
</script>
19+
20+
<style scoped>
21+
h1 {
22+
color: red;
23+
}
24+
</style>

packages/vite/src/node/ssr/ssrModuleLoader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ function proxyESM(id: string, mod: any) {
257257
return new Proxy(mod, {
258258
get(mod, prop) {
259259
if (prop === 'default') return defaultExport
260-
return mod[prop]
260+
return mod[prop] ?? defaultExport?.[prop]
261261
}
262262
})
263263
}

pnpm-lock.yaml

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)