question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

p tags get merged and className removed

See original GitHub issue

We’re using mdx together with next.js’ static export. Everything works perfect, besides one problem.

Certain p tags get merged together when the javascript has been run on the static html. The problem is that their className gets lost. As we use styled-components (would be the same problem with styled-jsx), the styling is broken at that point. An example is this page: https://docs-beta.prisma.io/1.13/understand-prisma/prisma-basics-server-services-data-model-avrp/ At the very bottom, you’ll see a paragraph with bad line-height. image

If you disable javascript in the browser (in chrome dev tools settings -> preferences -> Debugger -> Disable JavaScript), you can see, that it’s rendered correctly without javascript enabled, with an empty <p></p> tag before the p tag that will be broken.

image

I saw that mdx is using remark-squeeze-paragraphs which as far as I understand should fix exactly this problem. The actual remark-squeeze-paragraphs just removes not used p tags - so this should work.

Now the question is, where in the stack does this p tag merging happen and how can we fix it?

Thanks!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
johnocommented, Feb 15, 2019

I suspect that this is happening due to JS minification since we haven’t been able to reproduce. If you are able to create a repro without code minifying please open an issue and we can keep digging!

1reaction
shawnbotcommented, Sep 17, 2018

No test case yet, but I did confirm that disabling mangling in next.config.js fixes the problem for us:

module.exports = {
  webpack(config, {dev}) {
    // only disable mangling in production
    if (dev) {
      return config
    }
    for (const plugin of config.plugins) {
      // duck type: is this an UglifyJS plugin?
      if (plugin.options && plugin.options.uglifyOptions) {
        console.warn('*** disabling mangling in UglifyJS plugin ***')
        plugin.options.uglifyOptions.compress = {keep_fnames: true}
        plugin.options.uglifyOptions.mangle.keep_fnames = true
      }
    }
    return config
  }
}

I’ve attempted to trace the source of whatever is calling our mangled function name in our production bundles, but I haven’t figured it out yet. I’m 80% sure that the mangled icon function p() declaration is bleeding into MDX’s scope somehow, and whatever is rendering paragraphs is calling that function instead.

Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript dynamically adding and removing classes [duplicate]
Sure. You can use removeAttribute class. For example element.removeAttribute("class"); Then you'll get what you want. – smupyknight.
Read more >
Remove class name from tag nodes using HtmlAgilityPack
c# - I need to get rid of specific class names from html, for example: <table class="removeme"></table>
Read more >
Selectors - W3C
The following rule sets the style of all P elements that are children of BODY: ... the attribute selector for the default value...
Read more >
Cascade, specificity, and inheritance - Learn web development
At some point, you will be working on a project and you will find that the CSS you thought should be applied to...
Read more >
How Do You Remove Unused CSS From a Site?
To clean CSS with multiple pages just use that tool for all pages with different layouts. Then merge all exported CSS files to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found