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.

Vue.js => style tags are rendered twice

See original GitHub issue

Thank you for a nice plugin!

When using with Vue.js, the plugin, unfortunately, inlines the <style> tags from Vue.js single file components twice.

Please let me know, if such behavior is intended and the only choices for now are to either remove the duplicates by running regex on them:

postProcessHtml: function (context) {
    return context.html.replace(
        /(<style(.*?)<\/style>)/i,
        ''
    )
}

or to extract css in a separate file.

I’m currently using the regex method, but please let me know, if there is a way to not duplicate the <style> tags. Also, if you need a reproduction repo, I could quickly prepare that as well, if there’s a need for it.

Thank you very much!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:12 (8 by maintainers)

github_iconTop GitHub Comments

6reactions
drewlustrocommented, Sep 26, 2017

This is normal. It is similar to issues #105 and (loosely) #107.

Your endpoints are rendering and capturing the HTML verbatim. If Vue injects more on dynamic mount, it will be duplicate <style> markup.

Use postProcessHtml to sanitize your HTML into one unique set of CSS or JSS markup.


From the README doc:

// Manually transform the HTML for each page after prerendering,
// for example to set the page title and metadata in edge cases
// where you cannot handle this via your routing solution.
//
// The function's context argument contains two properties:
//
// - html :: the resulting HTML after prerendering)
// - route :: the route currently being processed
//            e.g. "/", "/about", or "/contact")
//
// Whatever is returned will be printed to the prerendered file.
postProcessHtml: function (context) {
  var titles = {
    '/': 'Home',
    '/about': 'Our Story',
    '/contact': 'Contact Us'
  }
  return context.html.replace(
    /<title>[^<]*<\/title>/i,
    '<title>' + titles[context.route] + '</title>'
  )
}
6reactions
thorningcommented, Sep 14, 2017

I have the same problem (I think). The spa-plugin does not add the styles twice, but they are added again by Vue when you mount on top of the prerendered dom.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Template renders twice in vue.js - Stack Overflow
Your template is and will be rendered multiple times - simply every time some of the reactive data it uses changes... You don't...
Read more >
Entry point rendered twice - Get Help - Vue Forum
In my app, the main App container is being rendered twice when I do a manual refresh of the page. I added a...
Read more >
[Solved]-Vue dynamic component renders twice-Vue.js
[Solved]-Vue dynamic component renders twice-Vue.js. Search. score:5 ... You have two <slot></slot> tags in DashboardItem.vue . Remove one ;).
Read more >
Rendering a list of Vue components - Learn web development
Vue components are written as a combination of JavaScript objects that ... v-for attaches to the element you want to repeat, and renders...
Read more >
How to Implement DFP (DoubleClick for Publishers) in React ...
How to Implement DFP (DoubleClick for Publishers) in React.js, Vue.js, and AMP? ... define ad slot, render ad element and display ads.
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