Giter VIP home page Giter VIP logo

Comments (11)

lodmfjord avatar lodmfjord commented on June 7, 2024 2

I did a pull request which fixes this issue.

#6

from talkr.

DoneDeal0 avatar DoneDeal0 commented on June 7, 2024 2

@gshilin Sorry for the huge delay in my answer, I had a lot of work and completely forgot to tweak this undefined navigator issue in ssr. Thanks @lodmfjord for taking care of that! I'll push the patch on npm by monday (hopefully this evening)!

from talkr.

DoneDeal0 avatar DoneDeal0 commented on June 7, 2024 1

I've just implemented the fix. It should be available on npm very soon.

from talkr.

gshilin avatar gshilin commented on June 7, 2024

navigator is not defined when is SSR mode. You use it to detect browser's language, but in this case it's impossible, so 'en' may be good enough instead of crash.

from talkr.

DoneDeal0 avatar DoneDeal0 commented on June 7, 2024

Hi Gshilin, thanks for using Talkr! Automatic language detection is an option. You can simply write

  <Talkr languages={{ en, fr }} defaultLanguage="en">
    <App />
  </Talkr>

to let the lib use "en" by default. However, I'll definitely add a fix in the future to avoid any crash with automatic browser detection in case it is not supported.

from talkr.

gshilin avatar gshilin commented on June 7, 2024

This happens in

const browserLanguage = navigator.language.split("-")[0];
and that's not inside any condition.
The solution I found is to simulate navigator:

if (typeof navigator === 'undefined') {
  navigator = {
    language: 'en-US',
  };
}

But it's quite ugly :(

from talkr.

DoneDeal0 avatar DoneDeal0 commented on June 7, 2024

The correct version is 2.0.2 or superior. The 2.0.1 has an export bug. Npm hasn't updated the package yet, please wait for this version to be available before updating your own package.

from talkr.

gshilin-sdb avatar gshilin-sdb commented on June 7, 2024

Looked at it. Unfortunately it'll return
Uncaught ReferenceError: navigator is not defined.
You have to use

typeof navigator !== 'undefined'

from talkr.

DoneDeal0 avatar DoneDeal0 commented on June 7, 2024

Why? The script checks if navigator exists, so it should not crash if the latter is undefined. detectBrowserLanguage && navigator ? browserLanguage : defaultLanguage.

from talkr.

gshilin-sdb avatar gshilin-sdb commented on June 7, 2024

image

from talkr.

gshilin-sdb avatar gshilin-sdb commented on June 7, 2024

The script checks if navigator has truthful value, but if it doesn't exist if will crash

from talkr.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.