Skip to content
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

Errors in MDX Rendering on first load #72

Closed
MaggieAppleton opened this issue Jun 26, 2020 · 9 comments
Closed

Errors in MDX Rendering on first load #72

MaggieAppleton opened this issue Jun 26, 2020 · 9 comments
Labels
bug Something isn't working

Comments

@MaggieAppleton
Copy link
Owner

MaggieAppleton commented Jun 26, 2020

Watch this loom video for a full explanation

MDX styling is behaving inconsistently, and not properly rendering if you go to a page directly for the first time.
If you refresh the page, everything is fixed. It only happens on first load.

The CSS doesn't load correctly, and any JavaScript libraries like GreenSock fail to execute. The issues happens in all .mdx posts.

I'm speculating it might have something to do with service workers or caching, but don't know how to debug it.

An example of the kind of rendering error that appear, and then disappear after a refresh:

2020-06-26 21-59-06 2020-06-26 22_06_53

@MaggieAppleton
Copy link
Owner Author

Another example of the same issue logged: #113

@MaggieAppleton
Copy link
Owner Author

Also having trouble getting libraries like greensock to load which I have a sneaky feeling is related to this: #105

@MaggieAppleton MaggieAppleton added the bug Something isn't working label Jan 10, 2021
@MaggieAppleton
Copy link
Owner Author

MaggieAppleton commented Jan 11, 2021

Structural diagrams of the codebase

Notes are passed through an <MDXRenderer> component and an <MDXProvider>, and then rendered through gatsby-theme-brain
image

All other .mdx files like essays, books, and illustrations are also passed through an <MDXRenderer> component and an <MDXProvider>, but don't go through gatsby-theme-brain. These pages have the same rendering bugs as the notes.
image

TLDR I don't think gatsby-theme-brain is what's causing the bug, but it could be something in the custom MDX provider situation.

All the .js components that are fed into the MDX renderer are written with emotion CSS-in-JS.

@theianjones
Copy link
Contributor

Service workers are always suspect. Thats why I turn them off :P

Since you are only clearing cookies and not having to jump into the service worker panel in dev tools to fix issues I dont think its service worker related.

My first hunch is that its the static site generated version of the page thats busted (the one that gatsby build builds). The way that we can test that is by runing yarn build in local dev and then yarn serve and going to an mdx post.

@MaggieAppleton
Copy link
Owner Author

I have a new working theory on what might be happening here @texastoland @theianjones

I think the CSS stylesheets are loading in the wrong order, or some of them are failing to load on the first render.
I use emotion and css-in-js for styling, so if webpack is randomly chucking stylesheets into headers it could be messing up the cascade.
This seems relevant: gatsbyjs/gatsby#1994

@texastoland
Copy link

I can't reproduce your original issues on the live site anymore:

  1. I can't replicate the Twitter styles at all.
  2. The duplicate image appears to be persistent now.
  3. The random paragraph spacing seems persistent too. It happens when the <p> is missing a generated class name that overrides an auto margin from Typography.js. I suspect it's related to MDX like @theianjones suggested.

@MaggieAppleton Are you seeing the same behavior? Did I miss any? I'd prefer to track them in separate issues if that's cool.

@MaggieAppleton
Copy link
Owner Author

MaggieAppleton commented Mar 7, 2021

I'm still seeing the same issues. Checked on multiple browsers and machines (Safari and Brave) and both behave the same.

To recreate it, I open a link a direct link to the post in a private window (https://maggieappleton.com/garden-history). The image duplicates and the random paragraph styles appear. If I then navigate back to the main page of garden notes by clicking on the menubar link ("Digital Garden") and click on that post directly ("A Brief History & Ethos of the Digital Garden"), the images and paragraph styles are all correct.

Do you see the same thing when you go through that flow?

Re: 1. - Unsure what you mean by the Twitter styles? The Tweets all load fine for me.

@texastoland I'll go split these up into multiple issues. Thanks!

@texastoland
Copy link

texastoland commented Mar 7, 2021

Oh I get it! The behavior is the reverse of #105. It's another interaction with Gatsby <Link/>. Feel free to close this in favor of the others (and optionally assign them to me).

@MaggieAppleton
Copy link
Owner Author

MaggieAppleton commented Mar 7, 2021

Cool, will do
Thanks 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants