@sigil-dev/grimoire 0.9.32 → 0.9.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -4
- package/src/client/router.ts +935 -927
- package/src/dev/hmr-client.ts +8 -0
- package/test/client-router.test.ts +904 -854
package/src/dev/hmr-client.ts
CHANGED
|
@@ -139,6 +139,12 @@ export const HMR_CLIENT_SOURCE = `
|
|
|
139
139
|
window.__hmrCapture__ = null;
|
|
140
140
|
}
|
|
141
141
|
|
|
142
|
+
// A navigation away (OAuth redirects, a slow callback) closes the socket
|
|
143
|
+
// before the next page arrives; reloading then would cancel it.
|
|
144
|
+
let leaving = 0;
|
|
145
|
+
window.addEventListener('beforeunload', () => { leaving = Date.now(); });
|
|
146
|
+
window.addEventListener('pageshow', () => { leaving = 0; });
|
|
147
|
+
|
|
142
148
|
function connect() {
|
|
143
149
|
const ws = new WebSocket(
|
|
144
150
|
(location.protocol === 'https:' ? 'wss' : 'ws') +
|
|
@@ -165,6 +171,8 @@ export const HMR_CLIENT_SOURCE = `
|
|
|
165
171
|
ws.onclose = () => {
|
|
166
172
|
console.log('[sigil hmr] disconnected, reconnecting...');
|
|
167
173
|
const retry = setInterval(async () => {
|
|
174
|
+
// still navigating away: let that finish instead (gives up after 15s)
|
|
175
|
+
if (leaving && Date.now() - leaving < 15000) return;
|
|
168
176
|
try {
|
|
169
177
|
await fetch('/', { method: 'HEAD' });
|
|
170
178
|
clearInterval(retry);
|