mnfst-render 0.5.0 → 0.5.1
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/manifest.render.mjs +28 -12
- package/package.json +1 -1
package/manifest.render.mjs
CHANGED
|
@@ -1943,23 +1943,39 @@ async function runPrerender(config) {
|
|
|
1943
1943
|
window.__manifestHydrateSnapshots = allSnapshots;
|
|
1944
1944
|
};
|
|
1945
1945
|
|
|
1946
|
-
// Wrap Alpine.initTree
|
|
1947
|
-
//
|
|
1948
|
-
//
|
|
1949
|
-
//
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1946
|
+
// Wrap Alpine.initTree. This MUST happen before any plugin calls initTree —
|
|
1947
|
+
// otherwise preloaded components (loaded eagerly by manifest.components before
|
|
1948
|
+
// Alpine starts walking the tree) get processed by the original initTree and
|
|
1949
|
+
// their hydrate targets are missed. We use a defineProperty setter on
|
|
1950
|
+
// window.Alpine so the wrap happens the instant Alpine's CDN script does
|
|
1951
|
+
// `window.Alpine = ...` — earlier than any event we could listen for.
|
|
1952
|
+
const wrap = (alpine) => {
|
|
1953
|
+
if (!alpine || alpine.__manifestRenderWrapped) return;
|
|
1954
|
+
if (typeof alpine.initTree !== 'function') return;
|
|
1955
|
+
alpine.__manifestRenderWrapped = true;
|
|
1956
|
+
const original = alpine.initTree.bind(alpine);
|
|
1957
|
+
alpine.initTree = function (root) {
|
|
1956
1958
|
try { snapshotSubtree(root || document.body); } catch (_) { /* graceful */ }
|
|
1957
1959
|
return original.apply(this, arguments);
|
|
1958
1960
|
};
|
|
1959
1961
|
};
|
|
1962
|
+
|
|
1963
|
+
// Setter trap: as soon as Alpine is assigned to window, wrap it.
|
|
1964
|
+
let _Alpine;
|
|
1965
|
+
try {
|
|
1966
|
+
Object.defineProperty(window, 'Alpine', {
|
|
1967
|
+
configurable: true,
|
|
1968
|
+
enumerable: true,
|
|
1969
|
+
get() { return _Alpine; },
|
|
1970
|
+
set(v) { _Alpine = v; wrap(v); },
|
|
1971
|
+
});
|
|
1972
|
+
} catch (_) { /* defineProperty failed, fall back to event listeners */ }
|
|
1973
|
+
|
|
1974
|
+
// Belt-and-braces: also try to wrap on alpine:init events in case some
|
|
1975
|
+
// environment beats the setter. wrap() is idempotent.
|
|
1960
1976
|
if (typeof document !== 'undefined') {
|
|
1961
|
-
document.addEventListener('alpine:init',
|
|
1962
|
-
document.addEventListener('alpine:initialized',
|
|
1977
|
+
document.addEventListener('alpine:init', () => wrap(window.Alpine));
|
|
1978
|
+
document.addEventListener('alpine:initialized', () => wrap(window.Alpine));
|
|
1963
1979
|
}
|
|
1964
1980
|
});
|
|
1965
1981
|
|