Skip to content
This repository has been archived by the owner on Apr 9, 2023. It is now read-only.

Style attribute binding gets overridden by pre-rendering #107

Closed
ricricucit opened this issue Sep 25, 2017 · 5 comments
Closed

Style attribute binding gets overridden by pre-rendering #107

ricricucit opened this issue Sep 25, 2017 · 5 comments
Assignees

Comments

@ricricucit
Copy link

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?

@drewlustro
Copy link
Collaborator

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.

@ricricucit
Copy link
Author

sounds good, thanks for the tip!

@ricricucit
Copy link
Author

@drewlustro I'm not 100% sure yet, but this seems to be a problem for router link as well. Seems to be rendered as regular URL and not getting picked up by the vue-router...

@drewlustro
Copy link
Collaborator

What is problematic? This plugin is supposed to render static, vanilla HTML.

router link is a custom element defined by vue-router. Thus, it would not (and should not) prerender as anything but an ordinary <a> link.

@ricricucit
Copy link
Author

ricricucit commented Oct 3, 2017

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants