-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
4.0.3 plugin results in flakey SSR behavior #80
Comments
Literally spent the whole day debugging this issue! Happy to come across this. Posted comment in this thread: gatsbyjs/gatsby#22908 (comment) Probably related to this change: e787e20#diff-7e93431ae23dd281591a7c6f2e6c8e3fb708cd3ba67ef2011d1607db8dd6804e Added I'm getting the following order:
While if I understand the code correctly expected order should be like this:
This might be crucial for proper Helmet SSR rendering. |
Ok, I don't think this is the bug with gatsby-plugin-material-ui since it is using public API Looks like the root cause of my issue (very similar to what was described by the topic starter) is the concurrency of html builds present in the gatsbyjs code itself. It could be that redefined More on why it matters: react-helmet readme and alternative react-helmet-async. Note: react-helmet-async doesn't seem to solve our "gatsbyjs specific" problem. Temporary(?) solution is to introduce your own Note that gatsby-plugin-react-helmet should be removed from the list of plugins in jest.config.js because we will be calling it's My gatsbyjs site gatsby-ssr.ts: import { ReplaceRendererArgs } from 'gatsby';
// @ts-ignore-next-line
import { replaceRenderer as muiReplaceRenderer } from 'gatsby-plugin-material-ui/gatsby-ssr';
// @ts-ignore-next-line
import { onRenderBody as reactHelmetOnRenderBody } from 'gatsby-plugin-react-helmet/gatsby-ssr';
export function replaceRenderer(replaceRendererArgs: ReplaceRendererArgs): void {
muiReplaceRenderer.call(null, replaceRendererArgs); // calls renderToString inside. Intentionally wo await
reactHelmetOnRenderBody.call(null, replaceRendererArgs); // calls Helmet.renderStatic()
} Unrelated to the bug - it would be great to hear from this project maintainers if Thanks |
On our site I also saw page metadata from one page ending up on another. This started happening after upgrading the site from version |
Solution proposed by @amalitsky works but it's a little bit hacky. In my personal project I have two branches with Gatsby v4 but one with mui v4 and second with v5. With v4 everything works perfectly and with v5 had same problems as @klittlepage. After some research in the history there was some similar problems (https://stackoverflow.com/questions/61442468/gatsby-react-helmet-generating-empty-title-on-ssr) with gatsby. I'm not sure but maybe also that is related with |
I resolved all my problems 🎉 Basically a solution was to replace |
I was debugging this issue and ended with a small reproducible example before finding this page — https://github.com/stldo/reproduce-material-ui-react-helmet-issue. I committed the public folder to the repo. In @rroslaniec solution of using |
Hi, thanks for your great work on the 4.x branch and support for mui v5 🎉 . I hit a snag when updating from
3.0.1
to4.0.3
. For some reason,head
elements inserted via gatsby-plugin-react-helmet are sporadically clobbered during SSR. As a concrete example I'm getting empty elements such as<title data-react-helmet="true"></title>
in places.This behavior is nondeterministic across builds. As a long shot, I experimented with placing this plugin both before and after
gatsby-plugin-react-helmet
given the use ofreplaceRenderer
in the4.x
line. That didn't resolve the problem.Any ideas are greatly appreciated!
The text was updated successfully, but these errors were encountered: