Skip to content

Always resetting the cookie when a PWA is installed #527

@maiconsanson

Description

@maiconsanson

Description

Based on the docs, the main strategy to detect the locale is:

  1. A locale prefix is present in the pathname (e.g. /de/about)
  2. A cookie is present that contains a previously detected locale
  3. The accept-language header is matched against the available locales
  4. The defaultLocale is used

This happens very well when accessing a browser by URL.

But the strategy fails if I access my app, which is a PWA, from installed on mobile.
The NEXT_LOCALE cookie is resetting when the app opens based on the accept-language header, even if I have this cookie value already.

Debugging my phone
If I access the root URL /, the previous NEXT_LOCALE is ignored. The locale is always en because I'm using it as the default language on my phone.

There is no problem with the app, only the NEXT LOCALE cookie is resetting. Other cookies are preserved and retrieved. In case I change my cellphone locale to Portuguese, the cookie is always pt no matter what.

Screenshot 2023-09-22 at 20 15 13

Important

  • "next": "14.1.0"
  • "next-intl": "3.5.1"
  • "@serwist/next': '8.4.3"
  • '@serwist/sw': '8.4.3'
  • It was tested with 2 Android phones with Chrome with the same result.
  • Before some next-intl update (I don't know which version) it did not happen.

Mandatory reproduction URL (CodeSandbox or GitHub repository)

https://github.com/maiconsanson/next-intl-pwa-ignoring-cookie

Reproduction description

Steps to reproduce:

  1. Configure your mobile device to the English locale en.
  2. Install the PWA (mobile) on Chrome.
  3. Open the app and change the locale by clicking on the link "Mude para Português".
  4. Close the PWA.
  5. Open the app again and notice that the locale is en, not the previous pt selected.

Repeat these steps directly on the browser and you seed that works normally.

Here is the production link to see in action:
https://intl-unable-find-locale.vercel.app/

Expected behaviour

The expected behavior is that the saved NEXT_LOCALE cookie value be used to define language when the PWA is installed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions