Comments (5)
Hey @rayliuca, fixing this in #288. Great bug report
from personal-site.
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.
Closing with merger of #288
from personal-site.
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.
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)
- issue with react-snap execuition HOT 1
- Menu with yellow border on mobile HOT 3
- npm install fails. HOT 3
- PAGES FAILING FOR NEW PACKAGE.JSON HOT 1
- node-sass v4.14.1 incompatible with node 15+
- Making subpages HOT 2
- CSS not rendering
- Is there any way to add link to each project in the project page ??? HOT 2
- ESlint Error on Windows HOT 1
- Migrating from Google Analytics UA to GA4 HOT 1
- Suggestion: Blog/Journal pages HOT 1
- Deploying from a Fork to GH Pages with Workflow HOT 4
- Can't modify Michael's name in navigation bar HOT 1
- Bolder underline for hyperlinks HOT 1
- Deployment timing out HOT 5
- Contribution Instructions HOT 1
- Deployment Instructions HOT 1
- Minified React error #418; #423; in production build HOT 3
- npm build not working HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from personal-site.