Giter Club home page Giter Club logo

Comments (5)

FoggyMtnDrifter avatar FoggyMtnDrifter commented on September 23, 2024

@hbjydev Can you take a look at this? I've done some work and pushed some changes in the develop branch with no luck. The switcher works properly when running the dev server locally, so the issue only occurs after build. I originally thought it might have been something to do with RSS because of some console errors but I completely removed it and the issue still persisted. I don't have the best knowledge when it comes to the i18n stuff and I'm not seeing anything extremely apparent that would be causing such an issue.

from rockylinux.org-gatsby.

mstg avatar mstg commented on September 23, 2024

I've taken a look and it seems to be that only the current locale is loaded at any given time. This happens because of the load: 'currentOnly' in gatsby-config.js. I see two ways that this can be fixed.

Either load all locales at all times:

diff --git a/gatsby-config.js b/gatsby-config.js
index f97d085..6bcd3f9 100644
--- a/gatsby-config.js
+++ b/gatsby-config.js
@@ -111,7 +111,7 @@ module.exports = {
           ],
           fallbackLng: 'en',
           lowerCaseLng: 'true',
-          load: 'currentOnly',
+          load: 'all',
           ns: ['translation'],
           returnObjects: true,
           interpolation: {

or instead of doing a client-side navigate, do a full page reload on locale change:

diff --git a/src/components/footer/index.jsx b/src/components/footer/index.jsx
index df7f43d..c34b750 100644
--- a/src/components/footer/index.jsx
+++ b/src/components/footer/index.jsx
@@ -163,11 +163,11 @@ const Footer = ({ pageContext: { locale: language } }) => {
             </h5>
             <select
               id="languagePicker"
-              onChange={(e) =>
-                navigate(
-                  `${e.target.value === 'en' ? `/` : `/${e.target.value}`}`
-                )
-              }
+              onChange={(e) => {
+                window.location.href = `${
+                  e.target.value === 'en' ? `/` : `/${e.target.value}`
+                }`;
+              }}
               name="language"
               className="mt-1 mr-2 block w-full pl-2 pr-8 py-1 text-sm text-black dark:text-white border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 focus:outline-none focus:ring-green-500 focus:border-green-500 sm:text-sm rounded-md"
               aria-label="Language Select"

I think option 2 is more favorable but that is for you all to decide

from rockylinux.org-gatsby.

hbjydev avatar hbjydev commented on September 23, 2024

Full page reload is definitely the favorable option. I'm using Lighthouse audits as a performance benchmark and we will take a big hit on load times if we do the load: 'all' version.

Can you open a PR for this @mstg?

from rockylinux.org-gatsby.

hbjydev avatar hbjydev commented on September 23, 2024

That way we get a Vercel preview build we can test it with

from rockylinux.org-gatsby.

mstg avatar mstg commented on September 23, 2024

@hbjydev I am also definitely in favor of performance and therefore option 2. Opened #26

from rockylinux.org-gatsby.

Related Issues (20)

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.