@markdy/astro 0.7.2 → 0.7.4
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 +2 -2
- package/src/Markdy.astro +43 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markdy/astro",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.4",
|
|
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.
|
|
40
|
+
"@markdy/renderer-dom": "0.7.4"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"astro": ">=4.0.0"
|
package/src/Markdy.astro
CHANGED
|
@@ -121,16 +121,21 @@ const {
|
|
|
121
121
|
</noscript>
|
|
122
122
|
</div>
|
|
123
123
|
|
|
124
|
-
<script is:inline>
|
|
124
|
+
<script is:inline data-cfasync="false">
|
|
125
125
|
// ── Rocket Loader rescue ──────────────────────────────────────────────────
|
|
126
|
-
// Cloudflare Rocket Loader rewrites <script type="module" src="...">
|
|
127
|
-
//
|
|
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:
|
|
129
128
|
//
|
|
130
|
-
//
|
|
131
|
-
//
|
|
132
|
-
//
|
|
133
|
-
//
|
|
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.
|
|
133
|
+
//
|
|
134
|
+
// `data-cfasync="false"` keeps this rescue script executable even when
|
|
135
|
+
// Rocket Loader is active. 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,39 @@ const {
|
|
|
139
144
|
function rescueModuleScripts() {
|
|
140
145
|
if (rescued) return;
|
|
141
146
|
rescued = true;
|
|
142
|
-
|
|
143
|
-
|
|
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 =
|
|
178
|
+
fix.src = src;
|
|
179
|
+
fix.setAttribute('data-cfasync', 'false');
|
|
148
180
|
document.head.appendChild(fix);
|
|
149
181
|
});
|
|
150
182
|
}
|