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

Html content from markdown disappears on refresh #2750

Closed
asgeir-s opened this issue Nov 2, 2017 · 10 comments
Closed

Html content from markdown disappears on refresh #2750

asgeir-s opened this issue Nov 2, 2017 · 10 comments

Comments

@asgeir-s
Copy link
Contributor

asgeir-s commented Nov 2, 2017

When clicking on a link in my webpage to get to another page everything works, but when I reload a page or go directly to a specific page (https://www.hallingdata.no/om-oss) the html-content from markdown flashes then disappears.

This problem is not present when running gatsby develop.

I have kind of found a workaround that I have used on this page (https://www.hallingdata.no/kontakt-takk/):

  const html = data.thankYouContactPage.childMarkdownRemark.html
  return (
      <Grid container className={classes.contentContainer} spacing={0}>
        <Grid item xs={12}>
          <Typography
            style={{display: "none"}}
            type="body1"
            gutterBottom
            align="justify"
            className={classes.content}
            dangerouslySetInnerHTML={{ __html: html }}
            hidden
          />
          <Typography
            type="body1"
            gutterBottom
            align="justify"
            className={classes.content}
            dangerouslySetInnerHTML={{ __html: html }}
          />
        </Grid>
      </Grid>
  )

This results in the page first displaying two instances of the html-content, then after 1 second or so, only one instance is displayed. If I remove the first instance of Typography the content flashes then disappears.

Query

export const pageQuery = graphql`
  query ThankYouContactContent {
    thankYouContactPage: file(relativePath: { eq: "content/kontakt-takk_page.md" }) {
      childMarkdownRemark {
        html
        frontmatter {
          header
        }
      }
    }
  }
`
@KyleAMathews
Copy link
Contributor

Can you build a simple site reproducing this problem? This could be a dozen different things. If there's something about gatsby that's causing this, we definitely want to solve it.

@asgeir-s
Copy link
Contributor Author

asgeir-s commented Nov 3, 2017

Thanks for the quick reply :)
Here is the sample: https://github.com/sogasg/gatsby-error

@KyleAMathews
Copy link
Contributor

Your sample site works fine once I remove the html.jsx file so the default html.js is used.

Generally you shouldn't override the html.js as it needs setup in a specific way — this is the default https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby/cache-dir/default-html.js

Your html.jsx wasn't using most of the required props.

https://www.gatsbyjs.org/docs/building-with-components/#html-component

@asgeir-s
Copy link
Contributor Author

asgeir-s commented Nov 4, 2017

Apparently, I was a little too eager when stripping down the sample. Sorry about that.

However, now I have removed the html.jsx file and the problem is still there (when I run npm run build and then npm run serve)

@KyleAMathews
Copy link
Contributor

KyleAMathews commented Nov 6, 2017

Looks like you ran into this facebook/react#5479

Use <div> instead.

Also, you should use the gatsby-link component.

Also, please never email me to remind me to look at your issue. If an issue is ever urgent, I'm available for paid consulting but otherwise, I provide support as I have time / motivation and nagging me is a good way for that motivation to disappear.

@asgeir-s
Copy link
Contributor Author

asgeir-s commented Nov 6, 2017

Thank you so much :)

I am genuinely sorry about that. It was not my intention to be "nagging" you.

@KyleAMathews
Copy link
Contributor

I am genuinely sorry about that. It was not my intention to be "nagging" you.

Yeah, sorry about that — there was a really big pile of issues earlier :-) but just for future reference, it's bad form to email maintainers directly unless you're paying them or best friends or something.

@cesarvarela
Copy link

Just got bitten by this, is possible to show a warning or something somewhere?

@alexabruck
Copy link

Bitten +1

dancormier added a commit to dancormier/dancormier.com-v4 that referenced this issue Sep 16, 2020
MarshalX added a commit to MarshalX/MarshalX that referenced this issue Oct 12, 2020
… (comment));

disable share button;
fix sections padding and font sizes.
dpip pushed a commit to dpip/aveva-apm-maturity-assessment-tool that referenced this issue Oct 23, 2020
@Nantris
Copy link

Nantris commented Jan 21, 2021

Same issue. Wrapping with div instead of p works, but and \n or <br /> we include within a blockquote inside of that div gets stripped out. Is there some way to accommodate inserting new lines easily?

Scratch that, Gatsby's cache became invalid somehow so it wasn't rebuilding.

edsu added a commit to umd-mith/airwaves that referenced this issue Jul 29, 2021
It appears that the lede sometimes appears and sometimes does not when
visiting the production site, and any static build. Under the devserver
everything seems fine.

I think that the cause for this is using dangerouslySetInnerHTML to set
HTML that has nested <p> tags?!?!

gatsbyjs/gatsby#2750 (comment)

I've replaced the <p> tag with a <div> for the lede and will see if this
fixes things at www.unlockingtheairwaves.org like it did for my local
build.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants