Open yzx9 opened 3 weeks ago
Try adding something like this to your .vitepress/config
for now: (you can directly use something like patch-package or pnpm patch too instead of monkey patching like this)
import { defineConfig } from 'vitepress'
export default defineConfig({
vite: {
plugins: [
{
name: 'patch-vitepress-symbol',
transform(code, id) {
if (id.includes('vitepress/dist/client/app/data.js')) {
return code.replace(
'const dataSymbol = Symbol();',
'const dataSymbol = "__vitepress_data__";'
)
}
}
}
]
}
})
It's happening because of chunking logic somewhere, but I'm not sure. Also, it works fine if defineAsyncComponent is used in markdown files 👀
Also, you shouldn't import Content
from vitepress. It's a global component. Remove it's import.
Describe the bug
Using
useData
with asyn components results in an error:Error: vitepress data not properly injected in app.
Reproduction
To replicate the issue, follow these steps in the provided StackBlitz project: https://stackblitz.com/edit/vite-5rgstx
Page.vue
file with the following code:import { useData } from 'vitepress'; const data = useData();
Page.vue
inLayout.vue
withimport Page from "./Page.vue"
and successfully build the project.const Page = defineAsyncComponent(() => import('./Page.vue'));
and attempt to rebuild. This results in an error indicating that VitePress data was not properly injected into the application.The error message is as follows:
Expected behavior
Build success
System Info
Additional context
I have encountered this bug since upgrading to v1.0.0-rc34. I'm unsure whether it's related to commit 9568fea
Validations