@markdy/astro 0.7.2 → 0.7.3

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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/Markdy.astro +40 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markdy/astro",
3
- "version": "0.7.2",
3
+ "version": "0.7.3",
4
4
  "description": "Astro island component for MarkdyScript animations.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -37,7 +37,7 @@
37
37
  "access": "public"
38
38
  },
39
39
  "dependencies": {
40
- "@markdy/renderer-dom": "0.7.2"
40
+ "@markdy/renderer-dom": "0.7.3"
41
41
  },
42
42
  "peerDependencies": {
43
43
  "astro": ">=4.0.0"
package/src/Markdy.astro CHANGED
@@ -123,14 +123,19 @@ const {
123
123
 
124
124
  <script is:inline>
125
125
  // ── Rocket Loader rescue ──────────────────────────────────────────────────
126
- // Cloudflare Rocket Loader rewrites <script type="module" src="..."> to a
127
- // proprietary type (e.g. "abc123-module") and then fails to execute them,
128
- // which silently kills ALL hydration logic in this component.
126
+ // Cloudflare Rocket Loader rewrites <script type="module" src="..."> in
127
+ // one of two ways, both of which prevent the hydration logic from running:
128
+ //
129
+ // A) Changes type="module" → type="{uuid}-module" (keeps tag in DOM)
130
+ // B) Wraps the entire tag in an HTML comment:
131
+ // <!--<script type="{uuid}-module" src="..."></script>-->
132
+ // making it invisible to querySelectorAll.
129
133
  //
130
134
  // This inline script is NOT touched by Rocket Loader (no src, no type attr).
131
- // It detects mangled module scripts by the Rocket Loader type pattern and
132
- // re-injects them dynamically dynamically-created scripts also bypass
133
- // Rocket Loader entirely.
135
+ // It rescues module scripts via two strategies:
136
+ // 1. Query the DOM for type$="-module" + src (covers case A)
137
+ // 2. Regex-parse the raw HTML for commented-out script tags (covers case B)
138
+ // Dynamically-created scripts bypass Rocket Loader entirely.
134
139
  (function () {
135
140
  if (window.__markdyRescue) return;
136
141
  window.__markdyRescue = true;
@@ -139,12 +144,38 @@ const {
139
144
  function rescueModuleScripts() {
140
145
  if (rescued) return;
141
146
  rescued = true;
142
- // Rocket Loader mangles type="module" → "{uuid}-module".
143
- // Re-inject as real module scripts so the browser executes them.
147
+
148
+ var srcs = [];
149
+
150
+ // Strategy 1: Rocket Loader kept the tag in DOM but changed the type.
151
+ // type="module" → type="{uuid}-module" (still has src attribute)
144
152
  document.querySelectorAll('script[type$="-module"][src]').forEach(function (s) {
153
+ srcs.push(s.src);
154
+ });
155
+
156
+ // Strategy 2: Rocket Loader COMMENTED OUT the script tag entirely:
157
+ // <!--<script type="{uuid}-module" src="..."></script>-->
158
+ // These are invisible to querySelectorAll, so we parse the raw HTML.
159
+ // We handle both attribute orderings (type-first or src-first).
160
+ var html = document.documentElement.innerHTML;
161
+ var reSrcFirst = /<!--<script\s[^>]*src="([^"]+)"[^>]*type="[^"]*-module"[^>]*>\s*<\/script>-->/g;
162
+ var reTypeFirst = /<!--<script\s[^>]*type="[^"]*-module"[^>]*src="([^"]+)"[^>]*>\s*<\/script>-->/g;
163
+ var m;
164
+ while ((m = reSrcFirst.exec(html)) !== null) { srcs.push(m[1]); }
165
+ while ((m = reTypeFirst.exec(html)) !== null) { srcs.push(m[1]); }
166
+
167
+ // Re-inject each found src as a real module script.
168
+ // Deduplicate first, then inject. Dynamically-created scripts bypass
169
+ // Rocket Loader entirely. Modules with the same URL are only executed
170
+ // once by the browser (cached), so re-injecting already-running scripts
171
+ // is safe.
172
+ var seen = {};
173
+ srcs.forEach(function (src) {
174
+ if (seen[src]) return;
175
+ seen[src] = true;
145
176
  var fix = document.createElement('script');
146
177
  fix.type = 'module';
147
- fix.src = s.src;
178
+ fix.src = src;
148
179
  document.head.appendChild(fix);
149
180
  });
150
181
  }