-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue with components using defineAsyncComponent causing navigation and direct link errors in VitePress #4417
Comments
Apply this patch: diff --git a/packages/docs/docs/.vitepress/theme/components/Layout.vue b/packages/docs/docs/.vitepress/theme/components/Layout.vue
new file mode 100644
index 0000000..111ad66
--- /dev/null
+++ b/packages/docs/docs/.vitepress/theme/components/Layout.vue
@@ -0,0 +1,9 @@
+<script setup lang="ts">
+import DefaultTheme from 'vitepress/theme'
+</script>
+
+<template>
+ <Suspense>
+ <DefaultTheme.Layout />
+ </Suspense>
+</template>
diff --git a/packages/docs/docs/.vitepress/theme/index.ts b/packages/docs/docs/.vitepress/theme/index.ts
index 43ae43e..6156cba 100644
--- a/packages/docs/docs/.vitepress/theme/index.ts
+++ b/packages/docs/docs/.vitepress/theme/index.ts
@@ -1,6 +1,7 @@
import type { AosOptions, ToasterOptions } from 'maz-ui'
-import { getAosInstance, installAos, installDialog, installToaster, installWait, vFullscreenImgInstall } from 'maz-ui'
+import type { Theme } from 'vitepress'
+import { getAosInstance, installAos, installDialog, installToaster, installWait, vFullscreenImgInstall } from 'maz-ui'
import * as components from 'maz-ui/components'
import { inBrowser } from 'vitepress'
import googleAnalytics from 'vitepress-plugin-google-analytics'
@@ -9,20 +10,19 @@ import DefaultTheme from 'vitepress/theme-without-fonts'
import { watch } from 'vue'
import ColorContainer from './components/ColorContainer.vue'
-
import ComponentDemo from './components/ComponentDemo.vue'
-
import DemoAuthPage from './components/DemoAuthPage.vue'
import DemoDashboardPage from './components/DemoDashboardPage.vue'
import DemoProductPage from './components/DemoProductPage.vue'
+import Layout from './components/Layout.vue'
import NpmBadge from './components/NpmBadge.vue'
import 'maz-ui/tailwindcss/tailwind.css'
-// import 'maz-ui/css/main.css'
import 'maz-ui/modules/plugins/aos/scss/index.scss'
import './main.css'
-const theme: typeof DefaultTheme = {
- ...DefaultTheme,
+export default {
+ extends: DefaultTheme,
+ Layout,
enhanceApp(ctx) {
googleAnalytics({
id: 'G-EM35TM23ZC',
@@ -73,6 +73,4 @@ const theme: typeof DefaultTheme = {
},
)
},
-}
-
-export default theme
+} satisfies Theme For the hydration mismatches, run: DEBUG=true pnpm -F=docs build && pnpm -F=docs preview Then you can see the issues on browser dev consoles and inspect server rendered markup using https://validator.w3.org/#validate_by_input. Alternatively, since you already have a nuxt playground you can use https://github.com/nuxt-modules/html-validator and review your components. |
Hooo, you rocks! Thanks a lot for your time and quick response. After testing with this fix, the MazChecklist error in his documentation page seems to come from something else (not from the async component). |
Doesn't seem to happen locally after adding Suspense 👀 Screen.Recording.2024-12-10.at.8.42.01.PM.movPS: Also it seems that you're (intentionally?) leaking your GitHub PAT. It might be better to use something like this instead - https://ungh.cc/repos/LouisMazel/maz-ui |
It's a little bit strange, I still have the MazChecklist error when I build and preview locally... It's a token key without any permission, just reading the star. But you're right, I should use ungh.cc for sure! |
Hmm, very weird. Can you maybe push your changes to some branch and I can check again locally? |
Yes for sure, you can checkout the branch The PR: LouisMazel/maz-ui#1193 |
Hmm, still not happening for me 😅 Maybe try Don't run git clean if you've local files. Try manually deleting node_modules, .vitepress/dist, .vitepress/.cache, .vitepress/.temp directories instead 👀 |
After cleaning the cache, all is good! I let you close the ticket? I think that's it for me. I just need to fix my hydration warnings :) |
Describe the bug
I encounter issues with Vue 3 components that use
defineAsyncComponent
. The issue manifests differently depending on the component:• For some components: The problem occurs only during navigation (e.g., navigating to the page from the menu). Directly loading the page (via direct link or page reload) works fine.
• For other components: The problem occurs even when directly loading the page (via direct link or reload).
In both cases, JavaScript errors are thrown, breaking the rendering and navigation. As a result:
• The page content may fail to render.
• Users are blocked from continuing to navigate unless they manually reload the page (which does not always resolve the issue).
This issue significantly impacts the usability of the documentation site.
Screenshot of a navigation bug :
Screenshot of direct link or reload bug :
Code of components :
Reproduction
Navigation bug :
Direct Link or Reload bug :
Expected behavior
Pages containing components that use defineAsyncComponent should render correctly, regardless of whether they are accessed via navigation or direct link. Navigation should not break, and no JavaScript errors should occur.
System Info
Additional context
This issue blocks users from properly viewing and navigating the documentation site. The workaround of manually reloading pages is unreliable, as some pages fail even with direct access.
Validations
The text was updated successfully, but these errors were encountered: