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.

'Flash' on rendered page when Vue takes over

See original GitHub issue

Hello - I have two routes that are pre-rendered on build using the plugin (Using v3.1.0 with Vue 2.5.13)

Same issue as reported in #131 and #156: “When I load a prerendered page I first see the prerendered page, then the page becomes white again before being hydrated by vue.”

I’ve recorded a demonstration here: https://youtu.be/pOPl00bcEn4

In Issue #156 @Tribex says: “As for when the static page tells Vue to take over… Technically it doesn’t. At the moment Vue will just replace all the prerendered DOM when it loads. (If you add the data-server-rendered=“true” attribute to your Vue mount point during prerendering, it should hydrate the DOM instead of replacing it.)” .

I have tried this, but it doesn’t appear to change anything:

<div id="app" data-server-rendered="true"></div>

My config is as follows:

new PrerenderSpaPlugin({
      // Path to compiled app
      staticDir: path.join(__dirname, '../dist'),
      // List of endpoints you wish to prerender
      routes: [ '/' ],
      // Workaround for async
      renderer: new Renderer({
        renderAfterDocumentEvent: 'render-event'
      }),
      headless: true
    })

Any idea why data-server-rendered=“true” does not appear to work? Thanks!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:19

github_iconTop GitHub Comments

8reactions
adrianolobocommented, Jul 20, 2018

I did this to automate this process of adding data-server-rendered

     postProcess(context) {
       context.html = context.html.replace('id="app"', 'id="app" data-server-rendered="true"');
       return context;
     },
6reactions
assembledadamcommented, Oct 3, 2018

@epistemery: Just came back to this (bit longer than I originally mentioned to @Tribex because life) and I believe i’ve resolved the obvious ‘white flash’ issue.

I had already worked out @totomobile43’s initial step of separating pre-rendered routes with dynamic routes, but was still getting the issue. What ended up fixing it for me was dynamically inserting the data-server-rendered="true" attribute as @adrianolobo mentions above.

My plugin config is as follows (slightly altered for brevity):

    new PrerenderSpaPlugin({
      // Path to compiled app
      staticDir: path.join(__dirname, './dist'),
      // Output directory
      outputDir: path.join(__dirname, './dist/rendered'),
      // List of endpoints you wish to prerender
      routes: [ '/homepage', '/contact' ],
      postProcess(context) {
        context.html = context.html.replace('id="app"', 'id="app" data-server-rendered="true"');
        return context;
      },
      // Workaround for async
      renderer: new Renderer({
        renderAfterDocumentEvent: 'render-event'
      }),
      headless: true
    })

And then my nginx config (snippet). Note you could add additional pre-redered routes to the location ~ (^/contact) { directive.

# pre-rendered routes
location = / {
    try_files $uri /rendered/homepage/index.html;
}
location ~ (^/contact) {
    try_files $uri /rendered/$1/index.html;
}

# all other dynamic routes
location / {
    try_files $uri /index.html;
}

@Tribex: I think between this and @totomobile43’s solution, we’ve worked it out, so I’m going to close the ticket. Feel free to re-open if necessary. Thanks guys 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to avoid {{expr}} flash to display on page before Vue.js ...
Right after page loaded, the literal {{expr}} will flash to display on the page before VueJS takes over and display the real binding...
Read more >
Common issues pre-rendering your Vue.js app (and how to fix ...
You get a flash of the wrong pre-render before your page loads. Combining pre-rendering with service worker SPA rules can lead to some ......
Read more >
Avoiding an ugly flash of route changes on first load - Vue Forum
hi folks. I've got an app working where I'm using firebase and vuex, and on first load, if a user is not signed...
Read more >
How to use Vue & Blade without flash of unstyled content?
I found that this package https://github.com/spatie/laravel-server-side-rendering allows server-side JS rendering, so when the page loads, the DOM and CSS ...
Read more >
Developing a Single Page App with Flask and Vue.js
Take a moment to read through the Introduction from the official Vue ... productionTip = false; new Vue({ router, render: (h) => h(App),...
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