Skip to content

Commit 32b57a8

Browse files
author
pooya parsa
committed
feat: always reload
1 parent 11d4f1c commit 32b57a8

File tree

4 files changed

+23
-60
lines changed

4 files changed

+23
-60
lines changed

app/app.vue

Lines changed: 15 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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">
@@ -22,11 +22,6 @@
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
}

app/css/loading.css

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,6 @@ h3.hasErrors {
4848
color: #D0021B;
4949
}
5050

51-
h3.manualReload {
52-
color: #F57F17;
53-
cursor: pointer;
54-
}
55-
5651
h4 {
5752
margin-bottom: 30px;
5853
font-size: 15px;

app/index.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
import Vue from 'vue'
22
import App from './app.vue'
33

4-
if (window._nuxtLoadingScreen) {
5-
location.reload(true) // Workaround
6-
} else {
7-
window._nuxtLoadingScreen = new Vue(App)
8-
}
4+
window._nuxtLoadingScreen = new Vue(App)

app/mixins/ws.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ export default {
8282
if (this.onWSData) {
8383
this.onWSData(data)
8484
}
85+
},
86+
87+
wsClose() {
88+
if (this.ws) {
89+
this.ws.close()
90+
delete this.ws
91+
}
8592
}
8693
}
8794
}

0 commit comments

Comments
 (0)