Skip to content

Commit

Permalink
fix: check exactly in proxyESM (#5512)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangyuang authored Nov 11, 2021
1 parent 87c0050 commit a17da55
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 2 deletions.
10 changes: 10 additions & 0 deletions packages/playground/ssr-vue/__tests__/ssr-vue.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ import fetch from 'node-fetch'

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

test('vuex can be import succeed by named import', async () => {
await page.goto(url + '/store')
expect(await page.textContent('h1')).toMatch('bar')

// raw http request
const storeHtml = await (await fetch(url + '/store')).text()
expect(storeHtml).toMatch('bar')
})


test('/about', async () => {
await page.goto(url + '/about')
expect(await page.textContent('h1')).toMatch('About')
Expand Down
3 changes: 2 additions & 1 deletion packages/playground/ssr-vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"dependencies": {
"example-external-component": "file:example-external-component",
"vue": "^3.2.21",
"vue-router": "^4.0.0"
"vue-router": "^4.0.0",
"vuex": "^4.0.2"
},
"devDependencies": {
"@vitejs/plugin-vue": "workspace:*",
Expand Down
24 changes: 24 additions & 0 deletions packages/playground/ssr-vue/src/pages/Store.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<template>
<h1>{{ foo }}</h1>
</template>

<script>
import { createStore } from 'vuex'
export default {
async setup() {
const store = createStore({
state: {
foo: 'bar'
}
})
return store.state
}
}
</script>

<style scoped>
h1 {
color: red;
}
</style>
2 changes: 1 addition & 1 deletion packages/vite/src/node/ssr/ssrModuleLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ function proxyESM(id: string, mod: any) {
return new Proxy(mod, {
get(mod, prop) {
if (prop === 'default') return defaultExport
return mod[prop]
return mod[prop] ?? defaultExport?.[prop]
}
})
}
2 changes: 2 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a17da55

Please sign in to comment.