11<template >
2- <div class =" loading-screen" :class =" { hide: allDone && !manualReload }" >
2+ <div class =" loading-screen" :class =" { hide: allDone }" >
33 <div class =" row" >
44 <transition appear >
55 <svg class =" logo" width =" 220" height =" 166" xmlns =" http://www.w3.org/2000/svg" >
2222 An error occured, please look at Nuxt.js terminal.
2323 </h3 >
2424 </div >
25- <div v-else-if =" manualReload" >
26- <h3 class =" manualReload" @click =" reloadPage" >
27- Please click here to continue or manually reload the page.
28- </h3 >
29- </div >
3025 <transition-group v-else >
3126 <div v-for =" bundle of bundles" :key =" bundle" class =" row" >
3227 <h3 >{{ bundle | capitalize }} bundle</h3 >
@@ -80,7 +75,7 @@ export default {
8075
8176 methods: {
8277 onWSData (data ) {
83- if (this ._closed ) {
78+ if (this ._reloading ) {
8479 return
8580 }
8681
@@ -91,7 +86,7 @@ export default {
9186 },
9287
9388 async fetchData () {
94- if (this ._closed ) {
89+ if (this ._reloading ) {
9590 return
9691 }
9792
@@ -116,7 +111,7 @@ export default {
116111 },
117112
118113 setTimeout () {
119- if (this ._closed ) {
114+ if (this ._reloading ) {
120115 return
121116 }
122117
@@ -125,7 +120,7 @@ export default {
125120 },
126121
127122 onData (data ) {
128- if (! data || ! data .states || this ._closed ) {
123+ if (! data || ! data .states || this ._reloading ) {
129124 return
130125 }
131126
@@ -149,64 +144,34 @@ export default {
149144
150145 // Try to show nuxt app if allDone and no errors
151146 if (! data .hasErrors && data .allDone && ! this .allDone ) {
152- this .showNuxtApp ()
147+ this .reload ()
153148 }
154149
155150 // Update state
156151 this .allDone = data .allDone
157152 this .hasErrors = data .hasErrors
158153 },
159154
160- reloadPage () {
161- return window .location .reload (true )
162- },
163-
164- async showNuxtApp () {
165- if (this ._closed ) {
155+ async reload () {
156+ if (this ._reloading ) {
166157 return
167158 }
168- this ._closed = true
159+ this .reloading = true
169160
170161 // Stop timers
171162 this .clearTimeout ()
172163
173164 // Close websockets connection
174- this .ws .close ()
165+ this .wsClose ()
166+
167+ // Clear console
168+ this .clearConsole ()
175169
176170 // Wait for transition (and hopefully renderer to be ready)
177171 await waitFor (500 )
178172
179- // If fetch does not exist, hard reload the page
180- if (typeof window .fetch !== ' function' ) {
181- return this .reloadPage ()
182- }
183-
184- // Fetch server side content
185- const fetchHTML = () => fetch (location .href ).then (res => res .text ())
186- const isLoading = html => html .includes (' <!-- nuxt_loading_screen -->' )
187- let html = await fetchHTML ()
188-
189- // Detect if still loading and wait a few more seconds
190- if (isLoading (html)) {
191- await waitFor (2000 )
192- html = await fetchHTML ()
193- if (isLoading (html)) {
194- // Give up
195- this .manualReload = true
196- return
197- }
198- }
199-
200- // Replace document with new page
201- document .open ()
202- document .write (html)
203- document .close ()
204-
205- // Destroy app
206- window ._nuxtLoadingScreen .$destroy ()
207-
208- // Clear console
209- this .clearConsole ()
173+ // Reload the page
174+ window .location .reload (true )
210175 }
211176 }
212177}
0 commit comments