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.
Files changed (2) hide show
  1. package/manifest.render.mjs +28 -12
  2. package/package.json +1 -1
@@ -1943,23 +1943,39 @@ async function runPrerender(config) {
1943
1943
  window.__manifestHydrateSnapshots = allSnapshots;
1944
1944
  };
1945
1945
 
1946
- // Wrap Alpine.initTree once Alpine is available. alpine:init fires before
1947
- // Alpine walks the tree for the first time, giving us the perfect insertion
1948
- // point. After wrapping, every initTree call (initial walk + every lazy
1949
- // component load) snapshots its subtree before Alpine processes it.
1950
- let installed = false;
1951
- const installInterceptor = () => {
1952
- if (installed || !window.Alpine || typeof window.Alpine.initTree !== 'function') return;
1953
- installed = true;
1954
- const original = window.Alpine.initTree.bind(window.Alpine);
1955
- window.Alpine.initTree = function (root) {
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', installInterceptor);
1962
- document.addEventListener('alpine:initialized', installInterceptor);
1977
+ document.addEventListener('alpine:init', () => wrap(window.Alpine));
1978
+ document.addEventListener('alpine:initialized', () => wrap(window.Alpine));
1963
1979
  }
1964
1980
  });
1965
1981
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mnfst-render",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "Render Manifest sites to static HTML for SEO",
5
5
  "type": "module",
6
6
  "bin": {