@absolutejs/absolute 0.19.0-beta.704 → 0.19.0-beta.706
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/dist/angular/browser.js +6 -4
- package/dist/angular/browser.js.map +3 -3
- package/dist/angular/index.js +71 -82
- package/dist/angular/index.js.map +10 -10
- package/dist/angular/server.js +70 -81
- package/dist/angular/server.js.map +10 -10
- package/dist/build.js +152 -84
- package/dist/build.js.map +15 -15
- package/dist/cli/index.js +330 -296
- package/dist/client/index.js +7 -4
- package/dist/client/index.js.map +3 -3
- package/dist/index.js +253 -153
- package/dist/index.js.map +24 -24
- package/dist/islands/index.js +9 -6
- package/dist/islands/index.js.map +5 -5
- package/dist/react/browser.js +7 -7
- package/dist/react/browser.js.map +2 -2
- package/dist/react/components/browser/index.js +101 -101
- package/dist/react/components/index.js +104 -104
- package/dist/react/components/index.js.map +2 -2
- package/dist/react/index.js +77 -88
- package/dist/react/index.js.map +10 -10
- package/dist/react/jsxDevRuntimeCompat.js +1 -6
- package/dist/react/jsxDevRuntimeCompat.js.map +3 -3
- package/dist/react/server.js +57 -71
- package/dist/react/server.js.map +8 -8
- package/dist/src/angular/components/defer-slot-templates.directive.d.ts +0 -7
- package/dist/src/angular/components/defer-slot.component.d.ts +2 -5
- package/dist/src/angular/components/image.component.d.ts +2 -5
- package/dist/src/angular/components/index.d.ts +4 -4
- package/dist/src/angular/components/stream-slot.component.d.ts +0 -3
- package/dist/src/angular/pageHandler.d.ts +6 -1
- package/dist/src/angular/ssrRender.d.ts +1 -1
- package/dist/src/build/buildAngularVendor.d.ts +3 -4
- package/dist/src/constants.d.ts +21 -0
- package/dist/src/core/ssrCache.d.ts +1 -1
- package/dist/src/core/wrapPageHandlerWithStreamingSlots.d.ts +1 -1
- package/dist/src/react/jsxDevRuntimeCompat.d.ts +3 -6
- package/dist/src/react/pageHandler.d.ts +2 -1
- package/dist/src/svelte/pageHandler.d.ts +2 -2
- package/dist/src/utils/defineConfig.d.ts +2 -2
- package/dist/src/utils/imageProcessing.d.ts +1 -1
- package/dist/src/utils/loadConfig.d.ts +38 -2
- package/dist/src/vue/components/Image.d.ts +3 -3
- package/dist/src/vue/components/index.d.ts +1 -1
- package/dist/src/vue/index.d.ts +1 -1
- package/dist/src/vue/pageHandler.d.ts +2 -1
- package/dist/svelte/index.js +52 -58
- package/dist/svelte/index.js.map +10 -10
- package/dist/svelte/server.js +46 -55
- package/dist/svelte/server.js.map +9 -9
- package/dist/vue/components/Image.js +18 -18
- package/dist/vue/components/Image.js.map +3 -3
- package/dist/vue/components/index.js +77 -62
- package/dist/vue/components/index.js.map +5 -5
- package/dist/vue/index.js +137 -142
- package/dist/vue/index.js.map +13 -13
- package/dist/vue/server.js +54 -77
- package/dist/vue/server.js.map +8 -8
- package/package.json +42 -42
- package/dist/angular/components/constants.js +0 -56
- package/dist/angular/components/core/streamingSlotRegistrar.js +0 -58
- package/dist/angular/components/core/streamingSlotRegistry.js +0 -114
- package/dist/angular/components/defer-slot-payload.js +0 -6
- package/dist/angular/components/defer-slot-templates.directive.js +0 -44
- package/dist/angular/components/defer-slot.component.js +0 -149
- package/dist/angular/components/image.component.js +0 -202
- package/dist/angular/components/index.js +0 -4
- package/dist/angular/components/stream-slot.component.js +0 -103
- package/dist/dev/client/constants.ts +0 -26
- package/dist/dev/client/cssUtils.ts +0 -307
- package/dist/dev/client/domDiff.ts +0 -226
- package/dist/dev/client/domState.ts +0 -421
- package/dist/dev/client/domTracker.ts +0 -61
- package/dist/dev/client/errorOverlay.ts +0 -184
- package/dist/dev/client/frameworkDetect.ts +0 -63
- package/dist/dev/client/handlers/angular.ts +0 -551
- package/dist/dev/client/handlers/angularRuntime.ts +0 -206
- package/dist/dev/client/handlers/html.ts +0 -363
- package/dist/dev/client/handlers/htmx.ts +0 -272
- package/dist/dev/client/handlers/react.ts +0 -108
- package/dist/dev/client/handlers/rebuild.ts +0 -153
- package/dist/dev/client/handlers/svelte.ts +0 -332
- package/dist/dev/client/handlers/vue.ts +0 -292
- package/dist/dev/client/headPatch.ts +0 -233
- package/dist/dev/client/hmrClient.ts +0 -251
- package/dist/dev/client/hmrState.ts +0 -14
- package/dist/dev/client/moduleVersions.ts +0 -62
- package/dist/dev/client/reactRefreshSetup.ts +0 -33
- package/dist/src/angular/components/constants.d.ts +0 -53
- package/dist/svelte/components/AwaitSlot.svelte +0 -39
- package/dist/svelte/components/AwaitSlot.svelte.d.ts +0 -2
- package/dist/svelte/components/Head.svelte +0 -144
- package/dist/svelte/components/Head.svelte.d.ts +0 -2
- package/dist/svelte/components/Image.svelte +0 -164
- package/dist/svelte/components/Image.svelte.d.ts +0 -5
- package/dist/svelte/components/Island.svelte +0 -71
- package/dist/svelte/components/Island.svelte.d.ts +0 -5
- package/dist/svelte/components/JsonLd.svelte +0 -21
- package/dist/svelte/components/JsonLd.svelte.d.ts +0 -2
- package/dist/svelte/components/StreamSlot.svelte +0 -41
- package/dist/svelte/components/StreamSlot.svelte.d.ts +0 -2
- package/dist/types/globals.d.ts +0 -121
|
@@ -1,272 +0,0 @@
|
|
|
1
|
-
import type {} from '../../../types/globals';
|
|
2
|
-
/* HTMX HMR update handler */
|
|
3
|
-
|
|
4
|
-
import { DOM_UPDATE_DELAY_MS } from '../constants';
|
|
5
|
-
import { patchDOMInPlace } from '../domDiff';
|
|
6
|
-
import {
|
|
7
|
-
saveDOMState,
|
|
8
|
-
restoreDOMState,
|
|
9
|
-
saveFormState,
|
|
10
|
-
restoreFormState,
|
|
11
|
-
saveScrollState,
|
|
12
|
-
restoreScrollState
|
|
13
|
-
} from '../domState';
|
|
14
|
-
import { processCSSLinks, waitForCSSAndUpdate } from '../cssUtils';
|
|
15
|
-
import { patchHeadInPlace } from '../headPatch';
|
|
16
|
-
import { detectCurrentFramework } from '../frameworkDetect';
|
|
17
|
-
import { type HTMXSavedState, type ScriptInfo } from '../../../types/client';
|
|
18
|
-
import { hmrState } from '../hmrState';
|
|
19
|
-
|
|
20
|
-
const parseHTMXMessage = (
|
|
21
|
-
html: string | { body?: string; head?: string } | null | undefined
|
|
22
|
-
) => {
|
|
23
|
-
let body: string | null = null;
|
|
24
|
-
let head: string | null = null;
|
|
25
|
-
if (typeof html === 'string') {
|
|
26
|
-
body = html;
|
|
27
|
-
} else if (html && typeof html === 'object') {
|
|
28
|
-
body = html.body || null;
|
|
29
|
-
head = html.head || null;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return { body, head };
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const applyHeadPatch = (htmxHead: string | null) => {
|
|
36
|
-
if (!htmxHead) {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const doPatchHead = () => {
|
|
41
|
-
patchHeadInPlace(htmxHead);
|
|
42
|
-
};
|
|
43
|
-
if (hmrState.isFirstHMRUpdate) {
|
|
44
|
-
setTimeout(doPatchHead, DOM_UPDATE_DELAY_MS);
|
|
45
|
-
} else {
|
|
46
|
-
doPatchHead();
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const handleHTMXBodyUpdate = (
|
|
51
|
-
htmxBody: string,
|
|
52
|
-
htmxHead: string | null,
|
|
53
|
-
htmxDomState: ReturnType<typeof saveDOMState>
|
|
54
|
-
) => {
|
|
55
|
-
const updateHTMXBodyAfterCSS = () => {
|
|
56
|
-
updateHTMXBody(htmxBody, htmxDomState, document.body);
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
if (htmxHead) {
|
|
60
|
-
applyHeadPatch(htmxHead);
|
|
61
|
-
const cssResult = processCSSLinks(htmxHead);
|
|
62
|
-
waitForCSSAndUpdate(cssResult, updateHTMXBodyAfterCSS);
|
|
63
|
-
} else {
|
|
64
|
-
updateHTMXBodyAfterCSS();
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
export const handleHTMXUpdate = (message: {
|
|
69
|
-
data: {
|
|
70
|
-
html?: string | { body?: string; head?: string } | null;
|
|
71
|
-
};
|
|
72
|
-
}) => {
|
|
73
|
-
const htmxFrameworkCheck = detectCurrentFramework();
|
|
74
|
-
if (htmxFrameworkCheck !== 'htmx') return;
|
|
75
|
-
|
|
76
|
-
if (window.__REACT_ROOT__) {
|
|
77
|
-
window.__REACT_ROOT__ = undefined;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
sessionStorage.setItem('__HMR_ACTIVE__', 'true');
|
|
81
|
-
|
|
82
|
-
const htmxDomState = saveDOMState(document.body);
|
|
83
|
-
const { body: htmxBody, head: htmxHead } = parseHTMXMessage(
|
|
84
|
-
message.data.html
|
|
85
|
-
);
|
|
86
|
-
|
|
87
|
-
if (!htmxBody) {
|
|
88
|
-
sessionStorage.removeItem('__HMR_ACTIVE__');
|
|
89
|
-
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
handleHTMXBodyUpdate(htmxBody, htmxHead, htmxDomState);
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
const cloneHmrListenerElements = (container: HTMLElement) => {
|
|
97
|
-
container
|
|
98
|
-
.querySelectorAll('[data-hmr-listeners-attached]')
|
|
99
|
-
.forEach((elem) => {
|
|
100
|
-
const cloned = elem.cloneNode(true) as Element; // eslint-disable-line @typescript-eslint/consistent-type-assertions
|
|
101
|
-
if (elem.parentNode) {
|
|
102
|
-
elem.parentNode.replaceChild(cloned, elem);
|
|
103
|
-
}
|
|
104
|
-
cloned.removeAttribute('data-hmr-listeners-attached');
|
|
105
|
-
});
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
const removeOldScripts = (container: HTMLElement) => {
|
|
109
|
-
const scriptsInNewHTML = container.querySelectorAll('script[src]');
|
|
110
|
-
scriptsInNewHTML.forEach((script) => {
|
|
111
|
-
if (!script.hasAttribute('data-hmr-client')) {
|
|
112
|
-
script.remove();
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
const addNewScripts = (container: HTMLElement, newScripts: ScriptInfo[]) => {
|
|
118
|
-
newScripts.forEach((scriptInfo) => {
|
|
119
|
-
const newScript = document.createElement('script');
|
|
120
|
-
const separator = scriptInfo.src.includes('?') ? '&' : '?';
|
|
121
|
-
newScript.src = `${scriptInfo.src + separator}t=${Date.now()}`;
|
|
122
|
-
newScript.type = scriptInfo.type;
|
|
123
|
-
container.appendChild(newScript);
|
|
124
|
-
});
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
const replaceInlineScript = (script: Element) => {
|
|
128
|
-
if (script.hasAttribute('data-hmr-client')) {
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
const newScript = document.createElement('script');
|
|
133
|
-
newScript.textContent = script.textContent || '';
|
|
134
|
-
newScript.type = script.getAttribute('type') || 'text/javascript';
|
|
135
|
-
if (script.parentNode) {
|
|
136
|
-
script.parentNode.replaceChild(newScript, script);
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
const reExecuteScripts = (container: HTMLElement, newScripts: ScriptInfo[]) => {
|
|
141
|
-
removeOldScripts(container);
|
|
142
|
-
addNewScripts(container, newScripts);
|
|
143
|
-
|
|
144
|
-
const inlineScripts = container.querySelectorAll('script:not([src])');
|
|
145
|
-
inlineScripts.forEach(replaceInlineScript);
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
const handleScriptsAndStructureChange = (
|
|
149
|
-
container: HTMLElement,
|
|
150
|
-
newScripts: ScriptInfo[]
|
|
151
|
-
) => {
|
|
152
|
-
cloneHmrListenerElements(container);
|
|
153
|
-
reExecuteScripts(container, newScripts);
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
const restoreCounterSpan = (
|
|
157
|
-
container: HTMLElement,
|
|
158
|
-
count: number | undefined
|
|
159
|
-
) => {
|
|
160
|
-
const newCountSpan = container.querySelector('#count');
|
|
161
|
-
if (newCountSpan && count !== undefined) {
|
|
162
|
-
newCountSpan.textContent = String(count);
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
const updateHTMXBody = (
|
|
167
|
-
htmxBody: string,
|
|
168
|
-
htmxDomState: ReturnType<typeof saveDOMState>,
|
|
169
|
-
container: HTMLElement
|
|
170
|
-
) => {
|
|
171
|
-
if (!container) return;
|
|
172
|
-
|
|
173
|
-
const countSpan = container.querySelector('#count');
|
|
174
|
-
const countValue = countSpan
|
|
175
|
-
? parseInt(countSpan.textContent || '0', 10)
|
|
176
|
-
: 0;
|
|
177
|
-
|
|
178
|
-
const savedState: HTMXSavedState = {
|
|
179
|
-
componentState: { count: countValue },
|
|
180
|
-
forms: saveFormState(),
|
|
181
|
-
scroll: saveScrollState()
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
const existingScripts = collectScripts(container);
|
|
185
|
-
|
|
186
|
-
const tempDiv = document.createElement('div');
|
|
187
|
-
tempDiv.innerHTML = htmxBody;
|
|
188
|
-
|
|
189
|
-
if (savedState.componentState.count !== undefined) {
|
|
190
|
-
restoreCounterSpan(tempDiv, savedState.componentState.count);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
const patchedBody = tempDiv.innerHTML;
|
|
194
|
-
const newScripts = collectScriptsFromElement(tempDiv);
|
|
195
|
-
const scriptsChanged = didScriptsChange(existingScripts, newScripts);
|
|
196
|
-
|
|
197
|
-
const htmlStructureChanged = didHTMLStructureChange(container, tempDiv);
|
|
198
|
-
|
|
199
|
-
const hmrScript = container.querySelector('script[data-hmr-client]');
|
|
200
|
-
|
|
201
|
-
patchDOMInPlace(container, patchedBody);
|
|
202
|
-
|
|
203
|
-
if (hmrScript && !container.querySelector('script[data-hmr-client]')) {
|
|
204
|
-
container.appendChild(hmrScript);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
requestAnimationFrame(() => {
|
|
208
|
-
restoreFormState(savedState.forms);
|
|
209
|
-
restoreScrollState(savedState.scroll);
|
|
210
|
-
restoreCounterSpan(container, savedState.componentState.count);
|
|
211
|
-
restoreDOMState(container, htmxDomState);
|
|
212
|
-
|
|
213
|
-
if (scriptsChanged || htmlStructureChanged) {
|
|
214
|
-
handleScriptsAndStructureChange(container, newScripts);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
if (window.htmx) {
|
|
218
|
-
window.htmx.process(container);
|
|
219
|
-
}
|
|
220
|
-
});
|
|
221
|
-
sessionStorage.removeItem('__HMR_ACTIVE__');
|
|
222
|
-
};
|
|
223
|
-
|
|
224
|
-
/* Shared helpers */
|
|
225
|
-
|
|
226
|
-
const collectScripts = (container: HTMLElement) =>
|
|
227
|
-
Array.from(container.querySelectorAll('script[src]')).map((script) => ({
|
|
228
|
-
src: script.getAttribute('src') || '',
|
|
229
|
-
type: script.getAttribute('type') || 'text/javascript'
|
|
230
|
-
}));
|
|
231
|
-
|
|
232
|
-
const collectScriptsFromElement = (elem: HTMLElement) =>
|
|
233
|
-
Array.from(elem.querySelectorAll('script[src]')).map((script) => ({
|
|
234
|
-
src: script.getAttribute('src') || '',
|
|
235
|
-
type: script.getAttribute('type') || 'text/javascript'
|
|
236
|
-
}));
|
|
237
|
-
|
|
238
|
-
const didScriptsChange = (oldScripts: ScriptInfo[], newScripts: ScriptInfo[]) =>
|
|
239
|
-
oldScripts.length !== newScripts.length ||
|
|
240
|
-
oldScripts.some((oldScript, idx) => {
|
|
241
|
-
const [oldBeforeQuery = ''] = oldScript.src.split('?');
|
|
242
|
-
const [oldSrcBase] = oldBeforeQuery.split('&');
|
|
243
|
-
const newScript = newScripts[idx];
|
|
244
|
-
if (!newScript) return true;
|
|
245
|
-
const [newBeforeQuery = ''] = newScript.src.split('?');
|
|
246
|
-
const [newSrcBase] = newBeforeQuery.split('&');
|
|
247
|
-
|
|
248
|
-
return oldSrcBase !== newSrcBase;
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
const normalizeHTMLForComparison = (element: HTMLElement) => {
|
|
252
|
-
const clone = element.cloneNode(true) as HTMLElement; // eslint-disable-line @typescript-eslint/consistent-type-assertions
|
|
253
|
-
const scripts = clone.querySelectorAll('script');
|
|
254
|
-
scripts.forEach((script) => {
|
|
255
|
-
if (script.parentNode) {
|
|
256
|
-
script.parentNode.removeChild(script);
|
|
257
|
-
}
|
|
258
|
-
});
|
|
259
|
-
const allElements = clone.querySelectorAll('*');
|
|
260
|
-
allElements.forEach((elem) => {
|
|
261
|
-
elem.removeAttribute('data-hmr-listeners-attached');
|
|
262
|
-
});
|
|
263
|
-
if (clone.removeAttribute) {
|
|
264
|
-
clone.removeAttribute('data-hmr-listeners-attached');
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
return clone.innerHTML;
|
|
268
|
-
};
|
|
269
|
-
|
|
270
|
-
const didHTMLStructureChange = (container: HTMLElement, tempDiv: HTMLElement) =>
|
|
271
|
-
normalizeHTMLForComparison(container) !==
|
|
272
|
-
normalizeHTMLForComparison(tempDiv);
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import type {} from '../../../types/globals';
|
|
2
|
-
/* React HMR update handler
|
|
3
|
-
Uses React Fast Refresh to hot-swap components while preserving state.
|
|
4
|
-
Code splitting ensures React lives in a shared chunk that stays cached,
|
|
5
|
-
so dynamic import of the rebuilt entry reuses the same React instance. */
|
|
6
|
-
|
|
7
|
-
import { hideErrorOverlay } from '../errorOverlay';
|
|
8
|
-
import { detectCurrentFramework } from '../frameworkDetect';
|
|
9
|
-
|
|
10
|
-
export const handleReactUpdate = (message: {
|
|
11
|
-
data: {
|
|
12
|
-
hasCSSChanges?: boolean;
|
|
13
|
-
hasComponentChanges?: boolean;
|
|
14
|
-
manifest?: Record<string, string>;
|
|
15
|
-
pageModuleUrl?: string;
|
|
16
|
-
primarySource?: string;
|
|
17
|
-
serverDuration?: number;
|
|
18
|
-
};
|
|
19
|
-
}) => {
|
|
20
|
-
const currentFramework = detectCurrentFramework();
|
|
21
|
-
if (currentFramework !== 'react') return;
|
|
22
|
-
|
|
23
|
-
const hasComponentChanges = message.data.hasComponentChanges !== false;
|
|
24
|
-
const hasCSSChanges = message.data.hasCSSChanges === true;
|
|
25
|
-
const cssPath =
|
|
26
|
-
message.data.manifest && message.data.manifest.ReactExampleCSS;
|
|
27
|
-
|
|
28
|
-
if (!hasComponentChanges && hasCSSChanges && cssPath) {
|
|
29
|
-
reloadReactCSS(cssPath);
|
|
30
|
-
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const refreshRuntime = window.$RefreshRuntime$;
|
|
35
|
-
const { serverDuration } = message.data;
|
|
36
|
-
const { pageModuleUrl } = message.data;
|
|
37
|
-
|
|
38
|
-
if (pageModuleUrl && refreshRuntime) {
|
|
39
|
-
applyRefreshImport(pageModuleUrl, refreshRuntime, serverDuration);
|
|
40
|
-
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// No module URL — shouldn't happen, but reload as safety fallback
|
|
45
|
-
window.location.reload();
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const sendTiming = (clientStart: number, serverDuration?: number) => {
|
|
49
|
-
if (window.__HMR_WS__) {
|
|
50
|
-
const clientMs = Math.round(performance.now() - clientStart);
|
|
51
|
-
const total = (serverDuration ?? 0) + clientMs;
|
|
52
|
-
window.__HMR_WS__.send(
|
|
53
|
-
JSON.stringify({ duration: total, type: 'hmr-timing' })
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
if (window.__ERROR_BOUNDARY__) {
|
|
57
|
-
window.__ERROR_BOUNDARY__.reset();
|
|
58
|
-
} else {
|
|
59
|
-
hideErrorOverlay();
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
const applyRefreshImport = (
|
|
64
|
-
moduleUrl: string,
|
|
65
|
-
refreshRuntime: { performReactRefresh: () => unknown },
|
|
66
|
-
serverDuration?: number
|
|
67
|
-
) => {
|
|
68
|
-
const clientStart = performance.now();
|
|
69
|
-
import(`${moduleUrl}?t=${Date.now()}`)
|
|
70
|
-
.then(() => {
|
|
71
|
-
refreshRuntime.performReactRefresh();
|
|
72
|
-
sendTiming(clientStart, serverDuration);
|
|
73
|
-
|
|
74
|
-
return undefined;
|
|
75
|
-
})
|
|
76
|
-
.catch((err) => {
|
|
77
|
-
console.warn(
|
|
78
|
-
'[HMR] React Fast Refresh failed, falling back to reload:',
|
|
79
|
-
err
|
|
80
|
-
);
|
|
81
|
-
window.location.reload();
|
|
82
|
-
});
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
const reloadReactCSS = (cssPath: string) => {
|
|
86
|
-
const existingCSSLinks = document.head.querySelectorAll<HTMLLinkElement>(
|
|
87
|
-
'link[rel="stylesheet"]'
|
|
88
|
-
);
|
|
89
|
-
existingCSSLinks.forEach((link) => {
|
|
90
|
-
const href = link.getAttribute('href');
|
|
91
|
-
if (!href) {
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
const hrefBase = (href.split('?')[0] ?? '').split('/').pop() ?? '';
|
|
95
|
-
const cssPathBase =
|
|
96
|
-
(cssPath.split('?')[0] ?? '').split('/').pop() ?? '';
|
|
97
|
-
if (
|
|
98
|
-
hrefBase === cssPathBase ||
|
|
99
|
-
href.includes('react-example') ||
|
|
100
|
-
cssPathBase.includes(hrefBase)
|
|
101
|
-
) {
|
|
102
|
-
const newHref = `${
|
|
103
|
-
cssPath + (cssPath.includes('?') ? '&' : '?')
|
|
104
|
-
}t=${Date.now()}`;
|
|
105
|
-
link.href = newHref;
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
};
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
import type {} from '../../../types/globals';
|
|
2
|
-
/* Rebuild, manifest, module-update, and error handlers */
|
|
3
|
-
|
|
4
|
-
import { REBUILD_RELOAD_DELAY_MS } from '../constants';
|
|
5
|
-
import {
|
|
6
|
-
hideErrorOverlay,
|
|
7
|
-
isRuntimeErrorOverlay,
|
|
8
|
-
showErrorOverlay
|
|
9
|
-
} from '../errorOverlay';
|
|
10
|
-
|
|
11
|
-
export const handleFullReload = () => {
|
|
12
|
-
setTimeout(() => {
|
|
13
|
-
window.location.reload();
|
|
14
|
-
}, REBUILD_RELOAD_DELAY_MS);
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export const handleManifest = (message: {
|
|
18
|
-
data: {
|
|
19
|
-
manifest?: Record<string, string>;
|
|
20
|
-
serverVersions?: Record<string, number>;
|
|
21
|
-
};
|
|
22
|
-
}) => {
|
|
23
|
-
window.__HMR_MANIFEST__ = message.data.manifest;
|
|
24
|
-
|
|
25
|
-
if (message.data.serverVersions) {
|
|
26
|
-
window.__HMR_SERVER_VERSIONS__ = message.data.serverVersions;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (!window.__HMR_MODULE_VERSIONS__) {
|
|
30
|
-
window.__HMR_MODULE_VERSIONS__ = {};
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
window.__HMR_MODULE_UPDATES__ = [];
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const HMR_FRAMEWORKS = ['angular', 'react', 'vue', 'svelte', 'html', 'htmx'];
|
|
37
|
-
|
|
38
|
-
const mergeRecord = (
|
|
39
|
-
source: Record<string, string | number>,
|
|
40
|
-
target: Record<string, string | number>
|
|
41
|
-
) => {
|
|
42
|
-
Object.keys(source)
|
|
43
|
-
.filter((key) => Object.prototype.hasOwnProperty.call(source, key))
|
|
44
|
-
.forEach((key) => {
|
|
45
|
-
const value = source[key];
|
|
46
|
-
if (value !== undefined) {
|
|
47
|
-
target[key] = value;
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
const mergeServerVersions = (
|
|
53
|
-
serverVersions: Record<string, number> | undefined
|
|
54
|
-
) => {
|
|
55
|
-
if (!serverVersions) return;
|
|
56
|
-
const existing = window.__HMR_SERVER_VERSIONS__ ?? {};
|
|
57
|
-
mergeRecord(serverVersions, existing);
|
|
58
|
-
window.__HMR_SERVER_VERSIONS__ = existing;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
const mergeModuleVersions = (
|
|
62
|
-
moduleVersions: Record<string, number> | undefined
|
|
63
|
-
) => {
|
|
64
|
-
if (!moduleVersions) return;
|
|
65
|
-
const existing = window.__HMR_MODULE_VERSIONS__ ?? {};
|
|
66
|
-
mergeRecord(moduleVersions, existing);
|
|
67
|
-
window.__HMR_MODULE_VERSIONS__ = existing;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
const mergeManifest = (manifest: Record<string, string> | undefined) => {
|
|
71
|
-
if (!manifest) return;
|
|
72
|
-
const existing = window.__HMR_MANIFEST__ ?? {};
|
|
73
|
-
mergeRecord(manifest, existing);
|
|
74
|
-
window.__HMR_MANIFEST__ = existing;
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
export const handleModuleUpdate = (message: {
|
|
78
|
-
data: {
|
|
79
|
-
framework?: string;
|
|
80
|
-
manifest?: Record<string, string>;
|
|
81
|
-
moduleVersions?: Record<string, number>;
|
|
82
|
-
serverVersions?: Record<string, number>;
|
|
83
|
-
};
|
|
84
|
-
}) => {
|
|
85
|
-
const hasHMRHandler = HMR_FRAMEWORKS.includes(message.data.framework || '');
|
|
86
|
-
|
|
87
|
-
if (!hasHMRHandler) {
|
|
88
|
-
window.location.reload();
|
|
89
|
-
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
mergeServerVersions(message.data.serverVersions);
|
|
94
|
-
mergeModuleVersions(message.data.moduleVersions);
|
|
95
|
-
mergeManifest(message.data.manifest);
|
|
96
|
-
|
|
97
|
-
if (!window.__HMR_MODULE_UPDATES__) {
|
|
98
|
-
window.__HMR_MODULE_UPDATES__ = [];
|
|
99
|
-
}
|
|
100
|
-
window.__HMR_MODULE_UPDATES__.push(message.data);
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
export const handleRebuildComplete = (message: {
|
|
104
|
-
data: {
|
|
105
|
-
affectedFrameworks?: string[];
|
|
106
|
-
manifest?: Record<string, string>;
|
|
107
|
-
};
|
|
108
|
-
}) => {
|
|
109
|
-
if (!isRuntimeErrorOverlay()) {
|
|
110
|
-
hideErrorOverlay();
|
|
111
|
-
}
|
|
112
|
-
if (window.__HMR_MANIFEST__) {
|
|
113
|
-
window.__HMR_MANIFEST__ = message.data.manifest;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
if (
|
|
117
|
-
message.data.affectedFrameworks &&
|
|
118
|
-
!message.data.affectedFrameworks.includes('angular') &&
|
|
119
|
-
!message.data.affectedFrameworks.includes('react') &&
|
|
120
|
-
!message.data.affectedFrameworks.includes('html') &&
|
|
121
|
-
!message.data.affectedFrameworks.includes('htmx') &&
|
|
122
|
-
!message.data.affectedFrameworks.includes('vue') &&
|
|
123
|
-
!message.data.affectedFrameworks.includes('svelte')
|
|
124
|
-
) {
|
|
125
|
-
const url = new URL(window.location.href);
|
|
126
|
-
url.searchParams.set('_cb', Date.now().toString());
|
|
127
|
-
window.location.href = url.toString();
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
export const handleRebuildError = (message: {
|
|
132
|
-
data: {
|
|
133
|
-
affectedFrameworks?: string[];
|
|
134
|
-
column?: number;
|
|
135
|
-
error?: string;
|
|
136
|
-
file?: string;
|
|
137
|
-
framework?: string;
|
|
138
|
-
line?: number;
|
|
139
|
-
lineText?: string;
|
|
140
|
-
};
|
|
141
|
-
}) => {
|
|
142
|
-
const errData = message.data || {};
|
|
143
|
-
showErrorOverlay({
|
|
144
|
-
column: errData.column,
|
|
145
|
-
file: errData.file,
|
|
146
|
-
framework:
|
|
147
|
-
errData.framework ||
|
|
148
|
-
(errData.affectedFrameworks && errData.affectedFrameworks[0]),
|
|
149
|
-
line: errData.line,
|
|
150
|
-
lineText: errData.lineText,
|
|
151
|
-
message: errData.error || 'Build failed'
|
|
152
|
-
});
|
|
153
|
-
};
|