Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Merged
merged 6 commits into from
May 14, 2025

Conversation

isolcat
Copy link
Contributor

@isolcat isolcat commented Apr 7, 2025

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.

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Apr 7, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Apr 8, 2025
Copy link
Collaborator

@OrbisK OrbisK left a 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.

@dosubot dosubot bot removed the lgtm This PR has been approved by a maintainer label Apr 10, 2025
@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Apr 11, 2025
@isolcat
Copy link
Contributor Author

isolcat commented Apr 11, 2025

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.

@isolcat isolcat requested a review from OrbisK April 11, 2025 13:15
@isolcat
Copy link
Contributor Author

isolcat commented May 12, 2025

@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!

OrbisK
OrbisK previously approved these changes May 12, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label May 12, 2025
@dosubot dosubot bot added size:XS This PR changes 0-9 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels May 14, 2025
@antfu antfu enabled auto-merge May 14, 2025 04:44
@antfu antfu changed the title fix(useGamepad): resolve SSR detection issues with <ClientOnly> docs(useGamepad): resolve SSR detection issues with <ClientOnly> May 14, 2025
@antfu antfu added this pull request to the merge queue May 14, 2025
Merged via the queue into vueuse:main with commit 589a319 May 14, 2025
8 checks passed
@isolcat isolcat deleted the fix/useGamepad-no-supported branch May 14, 2025 06:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm This PR has been approved by a maintainer size:XS This PR changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG | useSupported | SSR evaluation might cause hydration error when component is created
3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.