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

fix(nuxt): plugin injection on latest Nuxt 3 context #1433

Merged
merged 2 commits into from
Jul 11, 2022
Merged

Conversation

brownsugar
Copy link
Contributor

@brownsugar brownsugar commented Jul 8, 2022

As Nuxt 3 removed the legacy context (nuxt/framework#5630), the inject argument and nuxtState option is not available anymore.

Fixes #1428
fix #1432

@netlify
Copy link

netlify bot commented Jul 8, 2022

Deploy Preview for pinia-official canceled.

Name Link
🔨 Latest commit 5e0d305
🔍 Latest deploy log https://app.netlify.com/sites/pinia-official/deploys/62cc2582e533580008650499

@posva
Copy link
Member

posva commented Jul 8, 2022

Thanks, I will take a look. I think we will also need to migrate to nuxt/kit. It was removed in the past due to some missing features but it should be ready now

@pi0
Copy link
Contributor

pi0 commented Jul 8, 2022

Nuxt kit is now stable to migrate to but buntime part (of plugins) can be upgraded to bridge. Kit utils are only for module/build level not runtime.

Copy link
Member

@posva posva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Let's go with this for the moment as it works with Nuxt2,3 and bridge

packages/nuxt/src/templates/plugin.ts Outdated Show resolved Hide resolved
packages/nuxt/src/templates/plugin.ts Outdated Show resolved Hide resolved
@posva posva merged commit bd0c52f into vuejs:v2 Jul 11, 2022
@msonowal

This comment was marked as spam.

context.ssrContext.payload.pinia = pinia.state.value
}
} else {
const source = isVue2 ? context.nuxtState : context.payload
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this change necessary? 🤔
It created other problems: #1447

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because nuxtState is removed in Nuxt 3 nuxt/framework#5630

It's weird that I didn't get error when set ssr: false.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, thanks

@nathanchase
Copy link

nathanchase commented Jul 22, 2022

In Nuxt 3, I can get to $auth (auth module) by way of useNuxtApp() in components and composables, but how would you access it in a Pinia store?

In components, I usually just do:

const nuxtApp = useNuxtApp();
const authUser = nuxtApp.$auth.user;

but in a stores/store.ts, useNuxtApp is not available, so I'm not quite sure how to get to the context?

[nuxt] [request error] nuxt instance unavailable
  at Module.useNuxtApp (./.nuxt/dist/server/server.mjs:520:13)
  at $id_C1ltjrBOrk (./.nuxt/dist/server/server.mjs:10547:39)
  at async __instantiateModule__ (./.nuxt/dist/server/server.mjs:32909:3)

Is this issue the reason - change in context access?

Reference: Denoder/nuxt-module-alternatives#54

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

Successfully merging this pull request may close these issues.

inject is not a function PiniaNuxtPlugin Nux3 - inject is not a function
5 participants