next-intl icon indicating copy to clipboard operation
next-intl copied to clipboard

t.replace(...).replaceAll is not a function

Open MichalMoravik opened this issue 1 year ago • 2 comments

Description

Hi!

People using slightly older browsers trigger the following error in my Sentry:

t.replace(...).replaceAll is not a function

that's because replaceAll is kinda new function.

Would it be possible to change the usage of this in the project? It appears only at two places:

  1. https://github.com/amannn/next-intl/blob/cb74c29e9a494691f27445f4b2043c924a8713c0/packages/next-intl/src/shared/utils.tsx#L114 (the one that is relevant to my current error I assume)
  2. https://github.com/amannn/next-intl/blob/cb74c29e9a494691f27445f4b2043c924a8713c0/packages/next-intl/src/middleware/utils.tsx#L123 (have not seen error with this one yet but I think it might come if the first place gets changed and this not)

My users are hitting error boundary and cannot use the web at the moment.

Full Error Stack

{
message: t.replace(...).replaceAll is not a function, 
name: TypeError, 
stack: 
TypeError: t.replace(...).replaceAll is not a function
    at a (https://www.vasekvety.sk/_next/static/chunks/296-ae496176be3b700e.js:1:7719)
    at Object.e.matchesPathname (https://www.vasekvety.sk/_next/static/chunks/296-ae496176be3b700e.js:1:8149)
    at https://www.vasekvety.sk/_next/static/chunks/296-ae496176be3b700e.js:1:6444
    at Array.find (<anonymous>)
    at Object.e.getRoute (https://www.vasekvety.sk/_next/static/chunks/296-ae496176be3b700e.js:1:6388)
    at usePathname (https://www.vasekvety.sk/_next/static/chunks/296-ae496176be3b700e.js:1:2092)
// ... the rest is not relevant ...

Mandatory reproduction URL

Not needed really

Reproduction description

Steps to reproduce:

  • I don't think this is necessary; both the error and the docs mentioning replaceAll is a new function are descriptive enough

Expected behaviour

I expect that the templateToRegex function is run without any error at replaceAll() line

MichalMoravik avatar Feb 25 '24 22:02 MichalMoravik

I just created PR as well to help with this: https://github.com/amannn/next-intl/pull/885

MichalMoravik avatar Feb 25 '24 23:02 MichalMoravik

Hi @amannn! Thanks for the quick reply in the PR.

So the last user who had problem was using Chrome 60.0.3112 (2017) on Windows 8.1.

Another user has Chrome 81.0.4044. This version is from April 2020 just 4 months before the replaceAll was added.

replaceAll is just too new in my opinion. Generally it started to be supported 2021 onwards and there is a lot of people in Slovakia (where we get most users from) who haven't updated their browser for 3 years (even longer).


Regarding the failing tests. I actually ran pnpm run test locally before pushing but I saw only the last couple of lines saying PASS so I thought all passed. Sorry for that.

MichalMoravik avatar Feb 26 '24 08:02 MichalMoravik