Giter Club home page Giter Club logo

Comments (5)

notrueblood avatar notrueblood commented on June 13, 2024 1

Hey @rayliuca, fixing this in #288. Great bug report

from personal-site.

rayliuca avatar rayliuca commented on June 13, 2024

It appears this has something to do lazy loading. The tags would update properly if lazy loading is disabled. I imagine this is due to interactions between helmet and lazy, where the helmet scripts ran before the relevant chuck is loaded.

For now, I disabled lazy loading on my site because the performance hit was minimal, but a better solution is needed.

from personal-site.

notrueblood avatar notrueblood commented on June 13, 2024

Closing with merger of #288

from personal-site.

rayliuca avatar rayliuca commented on June 13, 2024

Hi @notrueblood,

I took a closer look today and found that this still doesn't solve the issue for the meta description tag. The title was fixed, but not the meta description.

from personal-site.

rayliuca avatar rayliuca commented on June 13, 2024

I tried to research helmet and react a bit more, but it appears to be very difficult if not impossible to make it work natively. The best way I can think of is to add an useEffect hook to a function that updates/adds the meta tag when the page finished loading/updating. Some relevant excerpt:

import { React, useEffect } from 'react';

function UpdateMetaDesc(MetaDec) {
  const MetaDescEle = document.querySelector('meta[name=description]');

  if (MetaDescEle) {
    if (MetaDescEle.getAttribute('content') !== MetaDec) {
      document.querySelector('meta[name="description"]').setAttribute('content', MetaDec);
    }
  } else {
    const meta = document.createElement('meta');
    meta.name = 'description';
    meta.content = MetaDec;
    document.getElementsByTagName('head')[0].appendChild(meta);
  }
}

const Main = (props) => {
  useEffect(() => {
    UpdateMetaDesc(props.description);
  });
  return (
    <HelmetProvider>
      <Analytics />
      <ScrollToTop />
      <div id="wrapper">
        <Navigation />
        <div id="main">
          {props.children}
        </div>
        {props.fullPage ? null : <SideBar />}
      </div>
      <Footer />
      <Helmet titleTemplate="Ray Liu | %s" defaultTitle="Ray Liu" defer={false}>
        {props.title && <title>{props.title}</title>}
        <meta name="description" content={props.description} />
      </Helmet>
    </HelmetProvider>
  );
};

If this is a good solution then I can open a pull request

from personal-site.

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.