@ecopages/react-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/react-router",
3
- "version": "0.2.0-alpha.40",
3
+ "version": "0.2.0-alpha.42",
4
4
  "description": "Client-side SPA router for EcoPages React applications",
5
5
  "keywords": [
6
6
  "ecopages",
@@ -32,8 +32,8 @@
32
32
  "directory": "packages/react-router"
33
33
  },
34
34
  "peerDependencies": {
35
- "@ecopages/core": "0.2.0-alpha.40",
36
- "@ecopages/react": "0.2.0-alpha.40"
35
+ "@ecopages/core": "0.2.0-alpha.42",
36
+ "@ecopages/react": "0.2.0-alpha.42"
37
37
  },
38
38
  "dependencies": {
39
39
  "react": "^19.2.6",
@@ -148,8 +148,9 @@ async function morphHead(newDocument) {
148
148
  },
149
149
  flushRerunScripts: () => {
150
150
  for (const script of pendingRerunScripts) {
151
+ const registeredRerun = getRegisteredRerunScript(script.scriptId);
151
152
  const replacement = document.createElement("script");
152
- const shouldBustModuleSrc = isExternalModuleRerunScript(script);
153
+ const shouldBustModuleSrc = isExternalModuleRerunScript(script) && !registeredRerun;
153
154
  for (const [name, value] of script.attributes) {
154
155
  if (name === "src" && shouldBustModuleSrc) {
155
156
  replacement.setAttribute(RERUN_SRC_ATTR, value);
@@ -160,6 +161,13 @@ async function morphHead(newDocument) {
160
161
  }
161
162
  replacement.textContent = script.textContent;
162
163
  const existingScript = findExistingRerunScript(script);
164
+ if (registeredRerun) {
165
+ if (!existingScript) {
166
+ document.head.appendChild(replacement);
167
+ }
168
+ registeredRerun();
169
+ continue;
170
+ }
163
171
  if (existingScript) {
164
172
  existingScript.replaceWith(replacement);
165
173
  continue;
@@ -184,6 +192,13 @@ function isExternalModuleRerunScript(script) {
184
192
  }
185
193
  return script.attributes.some(([name, value]) => name === "type" && value === "module");
186
194
  }
195
+ function getRegisteredRerunScript(scriptId) {
196
+ if (!scriptId) {
197
+ return null;
198
+ }
199
+ const runtimeWindow = window;
200
+ return runtimeWindow.__ECO_PAGES__?.rerunScripts?.[scriptId] ?? null;
201
+ }
187
202
  function createRerunScriptUrl(src) {
188
203
  const url = new URL(src, document.baseURI);
189
204
  url.searchParams.set("__eco_rerun", String(++rerunNonce));