-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
docs(useGamepad): resolve SSR detection issues with <ClientOnly> #4699
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we rename the demo.vue
to demo.client.vue
this should be done by default.
I tried to modify the SSR Compatibility description, and as you mentioned, I changed demo.vue to demo.client.vue. |
@OrbisK Hi, just wanted to kindly follow up on this PR. Please let me know if there's anything I should adjust. If everything looks good, feel free to merge it. Thanks! |
Description
Fixes the Gamepad API detection issue in SSR environments by wrapping the component content with
<ClientOnly>
. This resolves the issue where the demo incorrectly shows "not supported" even when the browser supports the Gamepad API, particularly when accessed via direct link.The problem occurs due to hydration mismatch between server-side rendering (where Gamepad API is unavailable) and client-side rendering. Using
<ClientOnly>
ensures the component is only rendered on the client side, where the API detection can be performed correctly.Fixes #4697
Reference link: https://vitepress.dev/guide/ssr-compat#clientonly
Additional context
This is a common issue with browser-only APIs in SSR environments. The current solution follows VitePress's recommended approach for handling components that rely on browser-specific APIs by using the built-in
<ClientOnly>
component.fixes #123
).