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

nuxt.hooks not working #1930

Closed
TBioucasEAE opened this issue Mar 13, 2023 · 8 comments
Closed

nuxt.hooks not working #1930

TBioucasEAE opened this issue Mar 13, 2023 · 8 comments
Labels

Comments

@TBioucasEAE
Copy link

Environment

Node: v16.19.1
NPM: 9.6.1
Nuxt: 3.2.3 with Nitro 2.2.3
Module version: v8.0.0-beta.10

Reproduction

Create a i18n.js plugin as described in the documentation.

Create a component with the following template:

<template>
  <nav>
    <NuxtLink :to="switchLocalePath('en')">English</NuxtLink>
    <NuxtLink :to="switchLocalePath('pt')">Português</NuxtLink>
  </nav>
</template>

<script setup lang="ts">
  const switchLocalePath = useSwitchLocalePath();
</script>

Describe the bug

While navigating between languages, i expected to see the console.log() from i18n.js but nothing gets printed in the console.

Also, when i change the file extension to .ts a typescript error shows up:

Argument of type '"i18n:beforeLocaleSwitch"' is not assignable to parameter of type 'HookKeys<RuntimeNuxtHooks>';
Argument of type '"i18n:localeSwitched"' is not assignable to parameter of type 'HookKeys<RuntimeNuxtHooks>';

I checked that this PR was created in order to use these two hooks, but somehow they don't seem to work at all.

Additional context

No response

Logs

No response

@ineshbose
Copy link
Collaborator

ineshbose commented Mar 13, 2023

Hi, I'd like to ensure that the hooks are working fine so I'm really hoping to investigate further into this. Could you provide the source code of your plugin and/or a replication over Stackblitz please?

Note: the change is available on edge-version.

@ineshbose ineshbose mentioned this issue Mar 13, 2023
7 tasks
@TBioucasEAE
Copy link
Author

TBioucasEAE commented Mar 13, 2023

hi @ineshbose and thanks for the reply.

There's a stackblitz replication.

As you can see, while changing language, the message gets updated by locale, but no console log is triggered from i18n.ts hooks.

Also, you can see the typescript errors that i mentioned in the i18n.ts file.

I also did try the edge version as mentioned here but still the hooks don't trigger.

@ineshbose
Copy link
Collaborator

Thanks for the replication - yes, it seems that the latest change has not been released on edge so the hooks aren't working. /cc @kazupon

https://www.npmjs.com/package/@nuxtjs/i18n-edge/v/8.0.0-beta.10-27972923.f3bacb5?activeTab=readme

Meanwhile, you can refer to v7 docs as the same for this purpose - https://v8.i18n.nuxtjs.org/guide/callbacks/#onbeforelanguageswitch

@ineshbose
Copy link
Collaborator

Hi @TBioucasEAE, can you please check on edge if it works now?

@TBioucasEAE
Copy link
Author

hi @ineshbose . I updated the version to edge, but still does not work.

I also updated the replicate to the edge version, so you can check that the hooks still don't seem to work.

@ineshbose
Copy link
Collaborator

The stackblitz doesn't seem updated - but I tested manually and you'll be able to see the logs in your browser console (the functions, hook and plugins are runtime)

image

@TBioucasEAE
Copy link
Author

@ineshbose yes, you are right. althougt the i18n.ts still throws errors, it seems to be working now in the replicate.

@TBioucasEAE
Copy link
Author

I can confirm now that after removing package-lock.json and node_modulesand run npm i locally, i can see the logs and also no erros in the i18n.ts file.

Many thanks for your suppor @ineshbose

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

No branches or pull requests

2 participants