-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
feat(nuxt): allow accessing NuxtPage
ref via pageRef
#19403
Conversation
|
I am more curious about what would be the use cases behind it. This to me feels like quite some code added for features that most of ppl don't need. And also be able to work around with a custom inject/provide etc. Other than that, I also feel the current design is a bit implicit, where the ref gets the child, not the component feels a bit counter-intuitive. This also makes it harder to keep type safety. |
I was planning to try another approach. |
I would first challenge the real-world use case of the original request, and see if there are better solutions to achieve what they need (maybe no need to mess with the ref) before discussing the design of API etc. |
@antfu In essence it's about having more control when make page transitions, whether that would access (animation) tweens, dom elements which or page components. More specially, "control" in terms of a page transition might entail more than solely animating/manipulating the page edit: I wanted to add a note about "most of ppl don't need". Nuxt is quite popular in the creative development realm of coding (link for reference) |
Hey @danielroe @antfu, what information do you need specifically to progress this? Does an example in Nuxt 2 help? This way you can see the use case in a demo instead of text |
That would be great β€οΈ |
I think I understand the intention, but the current approach is a bit hacky to me. I guess for this, maybe we could have something built-in to support |
Cool! I'll make a demo asap just to be sure the use case is clear |
Hey @danielroe and @antfu, I've made a quick example. It basically contains two concepts:
Even though I've added two concepts, it's not exhaustive. Another concept/example might be accessing data from an 3DPool (when working with WebGL) and manipulating/animating those before arriving at a new route or finishing the route navigation |
Hey @danielroe and @antfu, I wanted check in to see if you have everything you need from me for this and if I can help out in some way |
Hi @antfu & @danielroe, is there an update on this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm very much up for the concept behind this. If we can expose the exposed properties of the page component 'upwards' that seems good to me. But I am wary of the particular implementation here which is clever, but very involved and I fear might be breakable.
How about exposing a proxy that accesses whatever the page exposes instead? That way we wouldn't need to manipulate vnodes. It would add an extra property name but otherwise pretty simple. Something like:
const pageRef = ref()
// later
pageRef.value.page.someMethod()
Mind you, I haven't tried this. What do you think?
Pushed an implementation. Let me know what you think and feel free to update/amend. |
/trigger release |
π Release triggered! You can now install nuxt@npm:nuxt3@pr-19403 |
The implementation is working well and way simpler than what i did. I like it π |
Can you think a better API/name for the exposed property? Maybe |
Sure ! This would be less confusing ( |
Just one more idea - might we pass |
I think the tempalte transformation would transform |
NuxtPage
NuxtPage
ref via pageRef
π Linked issue
resolve #19268
β Type of change
π Description
Hi π this PR makes using
ref
on<NuxtPage>
possible.The idea behind this PR is to set a
ref
on the page component called withinRouteProvider
and expose it. ThenNuxtPage
component will also expose what has been exposed through theRouteProvider
's ref.I did some manuel tests, and didn't find any memory leaks.
π Checklist