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

nuxtApp.call #14805

Closed
3 of 4 tasks
pi0 opened this issue Sep 5, 2022 · 2 comments · Fixed by #20608
Closed
3 of 4 tasks

nuxtApp.call #14805

pi0 opened this issue Sep 5, 2022 · 2 comments · Fixed by #20608

Comments

@pi0
Copy link
Member

pi0 commented Sep 5, 2022

Describe the feature

Context: #14269 and #14723

While we try to restore context on best efforts, It is not always possible or convenient. There is an (intended to be internal) util callWithNuxt from #app can be used to use to restore context for async composables:

import { callWithNuxt } from '#app'

// unsupported transform context
const nuxtApp = useNuxtApp()
await something()
await callWithNuxt(navigateTo, ['/route', { replace: true }])

It is not convenient for DX because for performance reasons, we chose to accept second arg as arg array and that also it is not auto-imported. This utility is fundamentally bound to nuxtApp instance and can be exposed to public API:

const nuxtApp = useNuxtApp()
await something()
await nuxtApp.call(navigateTo, '/route', { replace: true })

Alternatives:

  • We also have defineAsync to resolve issue but still there is no guarantee transform method works everyever.
  • We have callWithNuxt which could be exposed as an auto import but it is not user friendly nor makes sense to use another auto import when nuxtApp is main context

Additional information

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

Final checks

@antfu
Copy link
Member

antfu commented Mar 13, 2023

For reference, @posva proposed a similar concept for Vue core: vuejs/core#7451. I think we could align with the naming convention and maybe use it underneath later.

@danielroe
Copy link
Member

Agreed. Might be worth waiting until the vue core PR is merged so we can align on the name.

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.

3 participants