question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

new function useOnClient or something like watchWithFilter to run on client only

See original GitHub issue

Hi,

I have used vueuse in my VueJS project a lot and recently I started working on Nuxt (SSR), the problem I am facing is I am having a hard time using some composable function that runs on a client like useWindowSize. You can check this conversation: https://github.com/nuxt/framework/discussions/1702

I asked about the same but didn’t get much luck: https://github.com/vueuse/vueuse/issues/881 https://github.com/nuxt/framework/discussions/1702

I think it will be great to provide a guide or something to quickly get started with SSR and vueuse.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:13 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
jbmollecommented, Nov 18, 2021

Hi, I have the same problem with Nuxt3 and useBreakpoints on a desktop. I create const smAndLarger = breakpoints.greater('sm') which is false on SSR and true on desktop. I have a menu <n-menu :mode="smAndLarger ? 'horizontal' : 'vertical' "></n-menu>. The menu is vertical at the begining and should be horizontal then but it always stays vertical except if I reduce the browser window and increase it again. Doing something like this in script setup, solves the problem:

const mobile = ref(true)
watch(smAndLarger, (newValue) => {
  mobile.value = newValue
}, { immediate: true })

and then <n-menu :mode="mobile ? 'horizontal' : 'vertical' "></n-menu>. So it seems the initial value after hydration doesn’t trigger template rendering.

1reaction
antfucommented, Nov 10, 2021

And I think your CSB also works for me image

(yes it’s initially zero since it comes from the server-side, you will need to wait for client-side hydration to have it updated.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use Apollo Client with Remix - Apollo GraphQL Blog
From the Remix docs: “This may ask you whether you want to install create-remix@latest . Enter y . It will only be installed...
Read more >
Server-side vs. client-only rules - Microsoft Support
Rules are either server-side or client-only based on the conditions and actions you apply to them. ... This rule uses all Exchange server...
Read more >
Call Server side functionality from the Client sid... - ServiceNow
Hi everyone, I had an issue today with getting the user's group ( simple gs.getUser().isMemberOf(' ') ) from Catalog UI Policy. As I....
Read more >
How do I detect whether I am on server on client in next.js?
It's running within a container. I am doing an http request with isomorphic-fetch to get data for my render. I'd like to do...
Read more >
How to use client-side only packages with SSR in Gatsby and ...
js to take advantage of static site generation or server-side rendering and its performance benefits because that's what Youtube/StackOverflow/ ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found