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.

Style attribute binding gets overridden by pre-rendering

See original GitHub issue

I build a simple “parallax” using vuejs style binding :style and I found out that the prerender-spa-plugin executed phantomjs, which added static inline styles (eg. style="-webkit-transform: translateY(0px);") which, once generated, overrides the actual style-binding of the app.

For this reason I would maybe propose the possibility of skipping inline-style attributes when pre-rendering the application…would that be easy to implement, or: does someone could point me towards a (good) solution to work around this issue?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
drewlustrocommented, Sep 26, 2017

Great idea!

I’m currently working on an adaptor of this that employs Chrome Headless via puppeteer instead of phantomJS, so we’ll soon have more robust API’s as that matures.


In terms of what you can do right now to solve this issue, consider using options.postProcessHtml by providing regex to strip out applicable:

<div class="foo" style="transform: translate3d(0, 0, 1);"> ... </div>
<!-- ➡️  -->
<div class="foo">... </div>

webpack.config.js

// 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>'
  )
}

Hope that helps. Cheers.

0reactions
ricricucitcommented, Oct 3, 2017

no, sorry, I’m not sure I should be the one closing issues 😛

Read more comments on GitHub >

github_iconTop Results From Across the Web

Style Precedence - Angular
Bindings take precedence over static attributes because they are dynamic. In the following case, class and [class] have similar specificity, but the [class] ......
Read more >
Angular2 innerHtml binding remove style attribute [duplicate]
My problem, that when I use innererHtml binding - angular2 remove all styles attributes. It's important for me, bacause in my task -...
Read more >
ASP.NET Core Razor component lifecycle | Microsoft Learn
The lifecycle methods can be overridden to perform additional operations in components during component initialization and rendering.
Read more >
Attribute, class, and style bindings
With attribute binding, you can improve accessibility, style your application ... The `class.special` binding overrides any value for the `special` class in ...
Read more >
nytimes/backbone.stickit - GitHub
"data-stickit-bind-val" attributes in the DOM. This allows for binding non-string values from a prerendered <select>, assuming that you are using jQuery or a ......
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