@absolutejs/absolute 0.19.0-beta.1064 → 0.19.0-beta.1066

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.
@@ -179,14 +179,19 @@ const updateHTMLBody = (
179
179
  const domSnapshot = snapshotDOMChanges(container);
180
180
 
181
181
  const existingScripts = collectScripts(container);
182
+ const oldInlineScripts = collectInlineScripts(container);
182
183
  const hmrScript = container.querySelector('script[data-hmr-client]');
183
184
  const tempDiv = document.createElement('div');
184
185
  tempDiv.innerHTML = htmlBody;
185
186
  const newScripts = collectScriptsFromElement(tempDiv);
187
+ const newInlineScripts = collectInlineScripts(tempDiv);
186
188
 
187
189
  const htmlStructureChanged = didHTMLStructureChange(container, tempDiv);
190
+ const scriptsChanged =
191
+ didScriptsChange(existingScripts, newScripts) ||
192
+ didInlineScriptsChange(oldInlineScripts, newInlineScripts);
188
193
 
189
- if (htmlStructureChanged || didScriptsChange(existingScripts, newScripts)) {
194
+ if (htmlStructureChanged || scriptsChanged) {
190
195
  patchDOMInPlace(container, htmlBody);
191
196
  restoreDOMChanges(container, domSnapshot, htmlBody);
192
197
  }
@@ -198,12 +203,12 @@ const updateHTMLBody = (
198
203
  restoreFormState(savedState.forms);
199
204
  restoreScrollState(savedState.scroll);
200
205
 
201
- if (
202
- didScriptsChange(existingScripts, newScripts) ||
203
- htmlStructureChanged
204
- ) {
206
+ // Only touch scripts/interactive elements when a script actually
207
+ // changed. A pure markup edit (e.g. a heading) leaves inline-script
208
+ // state and `addEventListener` handlers intact.
209
+ if (scriptsChanged) {
205
210
  cloneInteractiveElements(container);
206
- reExecuteScripts(container, newScripts);
211
+ reExecuteScripts(container, newScripts, oldInlineScripts);
207
212
  }
208
213
  });
209
214
  sessionStorage.removeItem('__HMR_ACTIVE__');
@@ -245,6 +250,7 @@ const updateHTMLBodyDirect = (
245
250
  const savedState = saveHTMLState();
246
251
  const domSnapshot = snapshotDOMChanges(container);
247
252
 
253
+ const oldInlineScripts = collectInlineScripts(container);
248
254
  const tempDiv = document.createElement('div');
249
255
  tempDiv.innerHTML = htmlBody;
250
256
  const newScripts = collectScriptsFromElement(tempDiv);
@@ -271,8 +277,7 @@ const updateHTMLBodyDirect = (
271
277
  container.appendChild(newScript);
272
278
  });
273
279
 
274
- const inlineScripts = container.querySelectorAll('script:not([src])');
275
- inlineScripts.forEach(replaceInlineScript);
280
+ reExecuteInlineScripts(container, oldInlineScripts);
276
281
  });
277
282
  sessionStorage.removeItem('__HMR_ACTIVE__');
278
283
  };
@@ -291,6 +296,21 @@ const collectScriptsFromElement = (elem: HTMLElement) =>
291
296
  type: script.getAttribute('type') || 'text/javascript'
292
297
  }));
293
298
 
299
+ /* Inline (non-src) scripts, excluding the HMR client. Captured by ordinal so
300
+ * an unchanged inline script can be skipped on re-execution — re-running it
301
+ * would reset its module/global state (e.g. `let count = 0`) on every edit. */
302
+ const collectInlineScripts = (elem: HTMLElement) =>
303
+ Array.from(
304
+ elem.querySelectorAll('script:not([src]):not([data-hmr-client])')
305
+ ).map((script) => script.textContent || '');
306
+
307
+ const didInlineScriptsChange = (
308
+ oldInline: string[],
309
+ newInline: string[]
310
+ ) =>
311
+ oldInline.length !== newInline.length ||
312
+ oldInline.some((content, idx) => content !== newInline[idx]);
313
+
294
314
  const didScriptsChange = (oldScripts: ScriptInfo[], newScripts: ScriptInfo[]) =>
295
315
  oldScripts.length !== newScripts.length ||
296
316
  oldScripts.some((oldScript, idx) => {
@@ -348,7 +368,11 @@ const removeOldScripts = (container: HTMLElement) => {
348
368
  });
349
369
  };
350
370
 
351
- const reExecuteScripts = (container: HTMLElement, newScripts: ScriptInfo[]) => {
371
+ const reExecuteScripts = (
372
+ container: HTMLElement,
373
+ newScripts: ScriptInfo[],
374
+ oldInlineScripts: string[]
375
+ ) => {
352
376
  removeOldScripts(container);
353
377
 
354
378
  newScripts.forEach((scriptInfo) => {
@@ -359,6 +383,24 @@ const reExecuteScripts = (container: HTMLElement, newScripts: ScriptInfo[]) => {
359
383
  container.appendChild(newScript);
360
384
  });
361
385
 
362
- const inlineScripts = container.querySelectorAll('script:not([src])');
363
- inlineScripts.forEach(replaceInlineScript);
386
+ reExecuteInlineScripts(container, oldInlineScripts);
387
+ };
388
+
389
+ /* Re-execute inline scripts by replacing them with fresh nodes, but skip any
390
+ * whose textContent is byte-identical to its previous counterpart (matched by
391
+ * ordinal). Skipping leaves the original execution's global bindings intact,
392
+ * so unrelated edits don't reset inline-script state. */
393
+ const reExecuteInlineScripts = (
394
+ container: HTMLElement,
395
+ oldInlineScripts: string[]
396
+ ) => {
397
+ const inlineScripts = container.querySelectorAll(
398
+ 'script:not([src]):not([data-hmr-client])'
399
+ );
400
+ inlineScripts.forEach((script, idx) => {
401
+ if (oldInlineScripts[idx] === (script.textContent || '')) {
402
+ return;
403
+ }
404
+ replaceInlineScript(script);
405
+ });
364
406
  };
package/dist/index.js CHANGED
@@ -35465,6 +35465,11 @@ var moduleServerPromise, getModuleServer = () => moduleServerPromise, runSequent
35465
35465
  for (const file5 of svelteFiles) {
35466
35466
  state.fileHashes.set(resolve41(file5), computeFileHash(file5));
35467
35467
  }
35468
+ const surgicallyHandled = state.svelteSurgicallyHandled ?? new Set;
35469
+ for (const file5 of svelteFiles) {
35470
+ surgicallyHandled.add(resolve41(file5));
35471
+ }
35472
+ state.svelteSurgicallyHandled = surgicallyHandled;
35468
35473
  const serverDuration = Date.now() - startTime;
35469
35474
  await runSequentially(svelteFiles, (changedFile) => broadcastSvelteModuleUpdate(state, changedFile, svelteFiles, serverDuration));
35470
35475
  scheduleSvelteBundleRebuild(state, svelteFiles, config2)();
@@ -36234,7 +36239,8 @@ var moduleServerPromise, getModuleServer = () => moduleServerPromise, runSequent
36234
36239
  if (isCssOnlyChange && svelteCssFiles.length > 0) {
36235
36240
  handleSvelteCssOnlyUpdate(state, svelteCssFiles, manifest, duration3);
36236
36241
  }
36237
- pagesToUpdate.forEach((sveltePagePath) => {
36242
+ const surgicallyHandled = state.svelteSurgicallyHandled;
36243
+ pagesToUpdate.filter((sveltePagePath) => !surgicallyHandled?.has(resolve41(sveltePagePath))).forEach((sveltePagePath) => {
36238
36244
  broadcastSveltePageUpdate(state, sveltePagePath, manifest, duration3);
36239
36245
  });
36240
36246
  }, handleAngularCssOnlyUpdate = (state, angularCssFiles, manifest, duration3) => {
@@ -36520,6 +36526,7 @@ var moduleServerPromise, getModuleServer = () => moduleServerPromise, runSequent
36520
36526
  });
36521
36527
  return files.every((f2) => handled.has(f2));
36522
36528
  }, performFullRebuild = async (state, config2, affectedFrameworks, filesToRebuild, startTime, onRebuildComplete) => {
36529
+ state.svelteSurgicallyHandled = undefined;
36523
36530
  const hasManifest = Object.keys(state.manifest).length > 0;
36524
36531
  const files = filesToRebuild ?? [];
36525
36532
  let allHandled = files.length > 0 && hasManifest;
@@ -39774,6 +39781,7 @@ var wrapPageHandlerWithStreamingSlots = (handler, options) => {
39774
39781
  init_constants();
39775
39782
  import { argv } from "process";
39776
39783
  var {env: env4 } = globalThis.Bun;
39784
+ import { websocket as elysiaWebSocketHandler } from "elysia/ws";
39777
39785
 
39778
39786
  // src/dev/devCert.ts
39779
39787
  import {
@@ -40042,8 +40050,13 @@ var networking = (app) => {
40042
40050
  try {
40043
40051
  app.compile();
40044
40052
  } catch {}
40053
+ app.server = liveServer;
40045
40054
  liveServer.reload({
40046
40055
  routes: {},
40056
+ websocket: {
40057
+ ...app.config.websocket ?? {},
40058
+ ...elysiaWebSocketHandler
40059
+ },
40047
40060
  fetch: (request) => app.fetch(request)
40048
40061
  });
40049
40062
  return app;
@@ -46586,5 +46599,5 @@ export {
46586
46599
  ANGULAR_INIT_TIMEOUT_MS
46587
46600
  };
46588
46601
 
46589
- //# debugId=25821650BFD4E73364756E2164756E21
46602
+ //# debugId=6A3DA19918ED0F0164756E2164756E21
46590
46603
  //# sourceMappingURL=index.js.map