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

Using the t method in computed will trigger a [Vue warn]: getCurrentInstance() called inside a computed getter. #2675

Closed
Red-Asuka opened this issue Jan 9, 2024 · 7 comments

Comments

@Red-Asuka
Copy link

Environment


  • Operating System: Darwin
  • Node Version: v20.3.1
  • Nuxt Version: 3.9.1
  • CLI Version: 3.10.0
  • Nitro Version: 2.8.1
  • Package Manager: pnpm@8.14.0
  • Builder: -
  • User Config: devtools, app, runtimeConfig, modules, i18n, site, plugins, css, postcss, vite, typescript, nitro, build, hooks
  • Runtime Modules: @nuxtjs/tailwindcss@6.10.4, @vueuse/nuxt@10.7.1, @nuxtjs/i18n@8.0.0, @pinia/nuxt@0.5.1, @zadigetvoltaire/nuxt-gtm@0.0.13, @nuxt/image@1.0.0-rc.1, @nuxtjs/sitemap@5.0.1, @nuxt/content@2.10.0
  • Build Modules: -

Reproduction

https://stackblitz.com/edit/github-y149ef?file=app.vue

Describe the bug

As long as the t method is used in computed, this warning will appear.

Additional context

No response

Logs

[Vue warn]: getCurrentInstance() called inside a computed getter. This is incorrect usage as computed getters are not guaranteed to be executed with an active component instance. If you are using a composable inside a computed getter, move it ouside to the setup scope.
@DouglasAR01
Copy link

I'm having the same issue

@WooHoo-Wu
Copy link

me too...

@BobbieGoede
Copy link
Collaborator

Looks like this warning was added yesterday to Vue vuejs/core@324e817. Related discussion here vuejs/core#9974 (useI18n gets mentioned 😄) and related issue vuejs/core#10001 and follow up issue vuejs/core#10038.

I haven't looked into it yet, but I'm guessing the warning is triggered by something upstream in vue-i18n. /cc @kazupon

@BobbieGoede
Copy link
Collaborator

@skirtles-code
Copy link

The warning has been reverted in Vue core, vuejs/core@2fd3905. I imagine there'll be a 3.4.7 soon to release that.

@BobbieGoede
Copy link
Collaborator

Looks like the usage of getCurrentInstance() in vue-i18n is fine based on this comment vuejs/core#9974 (comment).

As the warning has been removed and the usage shouldn't trigger the warning (usage is for debugging and done safely), I'll close this issue. And as mentioned this warning should be gone after the next Vue release!

@DouglasAR01
Copy link

DouglasAR01 commented Jan 9, 2024

Seems like this line triggers the warning https://github.com/intlify/vue-i18n-next/blob/master/packages/vue-i18n-core/src/composer.ts#L1784

I supposed so. I'm using computed properties to easily react to lang switches in some components (i.e. the Navbar), I used this approach some time ago (about beta 10 iirc). I removed the computed properties to avoid the issue and it worked well, I guess that approach isn't needed anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants