opral / inlang-paraglide-js

Tree-shakable i18n library build on the inlang ecosystem.
https://inlang.com/m/gerre34r/library-inlang-paraglideJs
23 stars 0 forks source link

Use Index access instead of `.at()` function to support legacy browsers #78

Closed testvinder closed 2 months ago

testvinder commented 2 months ago

We are seeing a lot of errors in Sentry from users with older Macs / Safari versions. It is due to the at() function not being available in older browsers. It is specifically this parts that causes the error.

        getLanguageFromUrl(url) {
            const pathWithLanguage = url.pathname.slice(normaliseBase(base).length);
            const lang = pathWithLanguage.split("/").filter(Boolean).at(0);
            if (runtime.isAvailableLanguageTag(lang))
                return lang;
            return defaultLanguageTag;
        },

Could you consider using traditional index access instead so it works for both older and newer browser?

LorisSigrist commented 2 months ago

That's an interesting observation, I was under the impression that the .at function was well supported. We can certainly change that!

testvinder commented 2 months ago

You can see the browser compatibility here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at#browser_compatibility

Safari added it on 2022-03-14 and everyone else before that so it is well supported, but we see quite a bit of traffic from Mac users running older versions. It would be great if you could change it.

LorisSigrist commented 2 months ago

Done in https://github.com/opral/monorepo/pull/2588