Comments (6)
not sure I understand your setup, but have you tried using a simple permanent CSS sibling selectors to handle this?
creating and blanking a whole stylesheet and bothering the DOM as well seems too much of an effort :)
If the nav/modal opens, apply a "toggle" class to the html or body element (the scroll container) and let the CSS do the work using the styles you already have, but instead of adding and removing the whole style element, turn it into a permanent selector in your global app style sheet which (by definition) would be inactive if the toggle class in the head or body is not set.
I presume the CSS to block the scrolling is only a couple of lines.
The router events could also make sure that "stop-scrolling" class is removed if you navigate to/from a different layout/route.
from head.
There’s definitely a few different ways to do this. Regardless I think this was very unexpected behaviour. If useHead adds something to the page from a component, I would expect it to clean up after itself when that component unmounts.
from head.
I would expect it to clean up after itself when that component unmounts.
hmm, dunno.
I get your point, but how is it supposed to know what of the stuff your component added for whatever reason should remain and what not? and under what circumstances?
Just because some component is unmounted doesn't mean the whole page (or head) should go with it - me thinks...
For your scenario it would indeed be useful to have it linked to the router events (or any other component's custom on-and-off events) in some way so it does indeed cleanup after itself -- or make the contents/attributes of these element "more" reactive.
I'm not yet using this, so I'm unfamiliar with the internals.
I plan to add link
elements and meta
that should "persist", but it seems I might run into a similar problem like you but for different reasons :D -- that's why I checked this issue in the first place.
Have fun.
from head.
Personally I would expect that anything added by useHead would get removed when the component that added it unmounts. If you wanted certain items to persist, you'd put them in your main app component or layout components that don't get unmounted (or are replaced with another instance when they do). Otherwise you'd have lots of orphaned tags and things would not behave deterministically. I'm assuming useHead already works this way and my orphaned style tag example is just a bug.
from head.
I see.
I am still a little ambivalent about the whole thing and who's responsible cleaning up their mess ;-)
I'm assuming useHead already works this way and my orphaned style tag example is just a bug.
I wouldn't be able to tell, but I guess I'll find out very soon.
However, it'll indeed be the app / layout component that's responsible for adding these tags.
Have a good time.
from head.
Confirming this is still an issue.
Seems like a reactivity problem with computed
from head.
Related Issues (20)
- default meta description is not getting replaced HOT 1
- How to get type of script from useHead()? HOT 5
- Options API Dynamic Title HOT 3
- Issues when transpiling typeScript into javaScript HOT 6
- useHead script `children` vulnerable to XSS HOT 4
- the requested module does not provide an export named 'default' HOT 1
- website link HOT 1
- useHead does not working with vue router HOT 3
- change icon not work HOT 3
- Dependency not met HOT 2
- Noscript still seems to not be working HOT 1
- How to add "custom-element" tag to script HOT 3
- Deduping from initial head not working HOT 4
- Optional chaining are not compiled to ES5 HOT 2
- @vueuse/head not working properly with vite-plugin-ssr in SSR mode HOT 6
- Why do tags stay despite route change? HOT 9
- Issue with useServerHead or useHead with Vue 2.7 + Vite + Vue Router HOT 3
- Vue 2.5 support HOT 1
- The installation guide link is pointing to a broken link HOT 2
- Google is lowering my indexed pages every day
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from head.