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
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix:Adjust the demo.vue file name and modify the SSR Compatibility de…
…scription.
  • Loading branch information
isolcat committed Apr 11, 2025
commit 5d88cacde8794bbdcacba87d9eb28ee19949e8d2
28 changes: 28 additions & 0 deletions 28 packages/core/useGamepad/demo.client.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<script setup lang="ts">
import { useGamepad } from '@vueuse/core'
import Gamepad from './components/Gamepad.vue'

const { isSupported, gamepads } = useGamepad()
</script>

<template>
<div>
<div v-if="!isSupported" flex="~ row" place="items-center content-center" items="center" space="x-4">
<i i-carbon-error text="5xl" opacity="50" />
<div flex="~ col">
<span text="2xl">Gamepad is not supported on this device.</span>
<span opacity="70">It seems your device does not support the Gamepad API. Check <a href="https://caniuse.com/gamepad">here</a> for a list supported devices.</span>
</div>
</div>
<div v-else-if="gamepads.length === 0" flex="~ row" place="items-center content-center" items="center" space="x-4">
<i i-carbon-game-console text="5xl" opacity="50" />
<div flex="~ col">
<span text="2xl">No Gamepad Detected</span>
<span opacity="50">Ensure your gamepad is connected and press a button to wake it up.</span>
</div>
</div>
<div v-else space="y-4">
<Gamepad v-for="gamepad in gamepads" :key="gamepad.id" :gamepad="gamepad" />
</div>
</div>
</template>
30 changes: 0 additions & 30 deletions 30 packages/core/useGamepad/demo.vue

This file was deleted.

12 changes: 4 additions & 8 deletions 12 packages/core/useGamepad/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,10 @@ Currently there are only mappings for the Xbox 360 controller. If you have contr

### SSR Compatibility

When using this component in SSR environments, wrap it with your framework's client-only component to avoid hydration mismatches:
When using this component in SSR environments, you have a few options to avoid hydration mismatches:

```vue
<template>
<ClientOnly>
<GamepadComponent />
</ClientOnly>
</template>
```
#### In Nuxt.js

In Nuxt, you can simply rename your component file with the `.client.vue` suffix (e.g., `GamepadComponent.client.vue`) which will automatically make it render only on the client side, avoiding hydration mismatches.

This ensures proper rendering across server and client environments.
Morty Proxy This is a proxified and sanitized view of the page, visit original site.