aralroca / next-translate-plugin

Next-translate plugin for i18n in Next.js 🌍 - Load page translations and use them in an easy way!
MIT License
31 stars 20 forks source link

Next translate plugin crashes the `global-error` page in Nextjs with App router. #82

Open MrBr opened 5 months ago

MrBr commented 5 months ago

What version of this package are you using? 3.0.0-canary.4

What operating system, Node.js, and npm version? Mac OS, NodeJs, Yarn 3.6.4

What happened? Using next-translate crashes global-error.tsx in the root of app router. The decorated component uses useParams which for some reason have null value in global-error.tsx (with use client directive) and when accessing lang property it crashes the page.

This line seems to be causing the issue https://github.com/aralroca/next-translate-plugin/blob/main/src/templateAppDir.ts#L162

    const searchParams = __useSearchParams()
    const params = __useParams()
    const detectedLang = params.lang ?? searchParams.get('lang')

What did you expect to happen? Page not to crash.

Are you willing to submit a pull request to fix this bug? I'm.

Bug-Hanter commented 4 months ago

faced the same issue