@ecopages/browser-router 0.2.0-alpha.40 → 0.2.0-alpha.42

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ecopages/browser-router",
3
- "version": "0.2.0-alpha.40",
3
+ "version": "0.2.0-alpha.42",
4
4
  "description": "Client-side router for Ecopages with view transitions support",
5
5
  "keywords": [
6
6
  "ecopages",
@@ -35,7 +35,7 @@
35
35
  "morphdom": "^2.7.8"
36
36
  },
37
37
  "peerDependencies": {
38
- "@ecopages/core": "0.2.0-alpha.40"
38
+ "@ecopages/core": "0.2.0-alpha.42"
39
39
  },
40
40
  "types": "./src/index.d.ts"
41
41
  }
@@ -154,6 +154,7 @@ export declare class DomSwapper {
154
154
  * via a query parameter nonce.
155
155
  */
156
156
  private isExternalModuleRerunScript;
157
+ private getRegisteredRerunScript;
157
158
  /**
158
159
  * Appends a nonce query parameter to a script URL to bust the browser's
159
160
  * module cache and force re-execution on navigation.
@@ -186,8 +186,9 @@ class DomSwapper {
186
186
  this.pendingHeadScripts = [];
187
187
  for (const script of this.pendingRerunScripts) {
188
188
  const targetParent = script.parent === "body" ? document.body : document.head;
189
+ const registeredRerun = this.getRegisteredRerunScript(script.scriptId);
189
190
  const replacement = document.createElement("script");
190
- const shouldBustModuleSrc = this.isExternalModuleRerunScript(script);
191
+ const shouldBustModuleSrc = this.isExternalModuleRerunScript(script) && !registeredRerun;
191
192
  for (const [name, value] of script.attributes) {
192
193
  if (name === "data-eco-rerun") {
193
194
  continue;
@@ -201,6 +202,13 @@ class DomSwapper {
201
202
  }
202
203
  replacement.textContent = script.textContent;
203
204
  const existingScript = this.findExistingRerunScript(targetParent, script);
205
+ if (registeredRerun) {
206
+ if (!existingScript) {
207
+ targetParent.appendChild(replacement);
208
+ }
209
+ registeredRerun();
210
+ continue;
211
+ }
204
212
  if (existingScript) {
205
213
  existingScript.replaceWith(replacement);
206
214
  continue;
@@ -482,6 +490,13 @@ class DomSwapper {
482
490
  }
483
491
  return script.attributes.some(([name, value]) => name === "type" && value === "module");
484
492
  }
493
+ getRegisteredRerunScript(scriptId) {
494
+ if (!scriptId) {
495
+ return null;
496
+ }
497
+ const runtimeWindow = window;
498
+ return runtimeWindow.__ECO_PAGES__?.rerunScripts?.[scriptId] ?? null;
499
+ }
485
500
  /**
486
501
  * Appends a nonce query parameter to a script URL to bust the browser's
487
502
  * module cache and force re-execution on navigation.