Skip to content

HTMLElement is not defined on Nuxt (SSR) #6

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

Closed
ojvribeiro opened this issue Sep 21, 2023 · 3 comments
Closed

HTMLElement is not defined on Nuxt (SSR) #6

ojvribeiro opened this issue Sep 21, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@ojvribeiro
Copy link

There's an error occorring on Nuxt 3 using this lib on SSR mode.

Minimal reproduction: https://stackblitz.com/edit/nuxt-starter-xtdjhc?file=app.vue

On Stackblitz the error can only be seen on terminal (not breaking the application):

image

On local and production, this error is shown as an error 500, thus breaking the execution of the app:

image


The current workaround is by wrapping the loop of links with a <ClientOnly> Nuxt component.

<ClientOnly>
  <ul class="flex flex-col gap-4 whitespace-nowrap">
    <li v-for="link in links" :key="link.href">
      <NuxtLink
        :to="`#${link.href}`"
        class="-m-3 p-3 transition-colors"
        :class="[
          isActive(link.href)
            ? 'cursor-default text-primary'
            : 'text-neutral-200 hover:text-neutral-400',
        ]"
      >
        {{ link.label }}
      </NuxtLink>
    </li>
  </ul>
</ClientOnly>
@smastrom
Copy link
Owner

Hi @ojvribeiro, thank you very much for raising the issue (and providing a reproduction).

I'll be releasing a fix in the next 30 minutes or so. In the meanwhile, you should be able to overcome the issue by using activeId instead of isActive.

<NuxtLink
  :to="`#${link.href}`"
  class="-m-3 p-3 transition-colors"
  :class="[
    activeId === link.href
      ? 'cursor-default text-primary'
      : 'text-neutral-200 hover:text-neutral-400',
  ]"
>
  {{ link.label }}
</NuxtLink>

Thank you again!

@ojvribeiro
Copy link
Author

Oh, that was fast 😄

Thanks a lot for the better workaround and the quick response.

@smastrom smastrom added the bug Something isn't working label Sep 22, 2023
@smastrom
Copy link
Owner

Hi @ojvribeiro, please update to the new version:

pnpm add vue-use-active-scroll@latest

Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants