Skip to content
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

Client-only page #24866

Closed
3 of 4 tasks
kingyue737 opened this issue Dec 22, 2023 · 6 comments · Fixed by #25037
Closed
3 of 4 tasks

Client-only page #24866

kingyue737 opened this issue Dec 22, 2023 · 6 comments · Fixed by #25037

Comments

@kingyue737
Copy link

kingyue737 commented Dec 22, 2023

Describe the feature

Importing a library that is not compatible with SSR in a page may result in an error like window is undefined.

<!-- /pages/page1.vue -->
<script setup>
import L from 'L' // L is a library that does not support SSR
</script>

<template>
<div id='L'>
  <!-- ... -->
</div> 
</template>

We need to manually extract it to a separate component to the components folder and import it in the page, even though this component may only be used once.

<!-- /components/PageComponent.vue -->
<script setup>
import L from 'L' // L is a library that does not support SSR
</script>

<template>
<div id='L'>
  <!-- ... -->
</div> 
</template>
<!-- /pages/page1.vue -->
<script setup>
</script>

<template>
<ClientOnly>
  <PageComponent />
</ClientOnly> 
</template>

Maybe we can add a clientOnly: boolean field to definePageMeta macro to improve DX. Wrapping this page to ClientOnly for end users.

I know we already have routeRules. However, I still want to server render the layout when navigating to this page.

Additional information

  • Would you be willing to help implement this feature?
  • Could this feature be implemented as a module?

Final checks

@ExEr7um
Copy link
Contributor

ExEr7um commented Dec 22, 2023

You can use routeRules to achieve that: https://nuxt.com/docs/guide/concepts/rendering#route-rules.

@kingyue737
Copy link
Author

kingyue737 commented Dec 22, 2023

You can use routeRules to achieve that: https://nuxt.com/docs/guide/concepts/rendering#route-rules.

Please read my last sentence.

I know we already have routeRules. However, I still want to server render the layout when navigating to this page.

routeRules will render all the things on client side when navigating to that page via address bar. But I want to render the layout on server side like other pages to keep it consistent but only leave the page content to client side.

Furthermore, some modules require SSR like nuxt-auth-utils. I don't know if turning off SSR for a certain page will disable this module on this page.

@mukhriddin-dev
Copy link

Good @danielroe

@zyp971018

This comment was marked as off-topic.

@SemionChi
Copy link

is someone on it?
would love to make my first contribution.

@mukhriddin-dev
Copy link

@danielroe fire

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants