Adding an empty class throws error with @vueuse/head
See original GitHub issueEnvironment
- Operating System:
Linux
- Node Version:
v16.14.2
- Nuxt Version:
3.0.0-rc.14
- Nitro Version:
1.0.0
- Package Manager:
npm@7.17.0
- Builder:
vite
- User Config:
-
- Runtime Modules:
-
- Build Modules:
-
Reproduction
https://stackblitz.com/edit/nuxt-starter-kn7cz5?file=package.json
Describe the bug
This app.vue:
<script lang="ts" setup>
const bodyClass = ref('');
onMounted(() => {
window.addEventListener('scroll', (e) => {
bodyClass.value = window.top.scrollY > 100 ? 'fixed-header' : '';
});
});
</script>
<template>
<Body :class="bodyClass" />
<div style="height: 2000px"></div>
</template>
…throws the following error in console:
index.mjs?v=f97dfb0a:66 Uncaught (in promise) DOMException: Failed to execute 'add' on 'DOMTokenList': The token provided must not be empty.
at https://nuxt-starter-kn7cz5--3000.local-credentialless.webcontainer.io/_nuxt/node_modules/@unhead/vue/dist/index.mjs?v=f97dfb0a:66:25
at Array.forEach (<anonymous>)
at setAttrs (https://nuxt-starter-kn7cz5--3000.local-credentialless.webcontainer.io/_nuxt/node_modules/@unhead/vue/dist/index.mjs?v=f97dfb0a:57:29)
at renderDOMHead (https://nuxt-starter-kn7cz5--3000.local-credentialless.webcontainer.io/_nuxt/node_modules/@unhead/vue/dist/index.mjs?v=f97dfb0a:142:7)
Furthermore, the class fixed-header
gets correctly set when scrolling down, but does not get removed, when scrolling up again.
The problem was introduced in RC12 and persists up to RC14. RC11 does not throw the error and removes the class correctly.
Additional context
No response
Logs
No response
Issue Analytics
- State:
- Created 10 months ago
- Comments:8 (1 by maintainers)
Top Results From Across the Web
Show class if input:invalid:not(:empty) in vue.js - Stack Overflow
This solution shows a class, but when I change anything in the input, no reflesh. This has-error class is here permanent. SOLVED input:not(: ......
Read more >How to avoid empty class in Vue with null - Medium
Scenario 1: Using Empty String '' In this example, we're saying that if isBold is truthy, it will set the class to be...
Read more >Empty class attribute applied by default to rendered ... - GitHub
Define default styles that only apply when another class is not applicable. · Insert a with no classes defined. · Observe that the...
Read more >Models and Collections for Vue.js - Vue Models & Collections
If no value for model is given, it will add a new empty model. The added model will be returned, or an array...
Read more >empty - CSS: Cascading Style Sheets - MDN Web Docs
The :empty CSS pseudo-class represents any element that has no children. Children can be either element nodes or text (including whitespace) ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
it seems, setting
bodyClass
to an empty string is the cause of the problem. so this is a workaround:but what if i do not want a class at all?
Hey everyone, so this is indeed a bug and a fix is vailable in @vueuse/head 1.0.18.
You can upgrade by deleting lock file / node_modules and re-installing or manually adding this version.
Let me know if you have any issues with that.
Additionally, I’d recommend you switch to the new class API, which would look like this:
Similar to the Vue class API. You can also make use of the DOM events API to clean up your code too.
Please consult the unhead documentation to read more about the new features https://unhead.harlanzw.com/