mnfst-render 0.4.2 → 0.4.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.
@@ -956,6 +956,7 @@ function markPrerenderedManifestComponents(html) {
956
956
  return html.replace(/<(x-[a-z][\w-]*)([^>]*)>/gi, (full, tag, attrs) => {
957
957
  const a = attrs || '';
958
958
  if (/\bdata-pre-rendered\s*=/i.test(a) || /\bdata-processed\s*=/i.test(a)) return full;
959
+ if (/\bdata-prerender-hydrate\b/i.test(a)) return full; // Inside data-hydrate island — skip
959
960
  const spacer = /\S/.test(a) ? ' ' : '';
960
961
  return `<${tag}${a}${spacer}data-pre-rendered="1">`;
961
962
  });
@@ -1161,14 +1162,24 @@ function loadAllLocaleContentData(manifest, rootDir, locales) {
1161
1162
  */
1162
1163
  function buildSubstitutionPairs(defaultLocaleData, targetLocaleData) {
1163
1164
  const pairs = [];
1164
- for (const [key, rawDefault] of Object.entries(defaultLocaleData)) {
1165
- const rawTarget = targetLocaleData[key];
1166
- if (rawTarget == null || rawDefault == null) continue;
1167
- const from = String(rawDefault).trim();
1168
- const to = String(rawTarget).trim();
1169
- if (!from || from === to) continue;
1170
- pairs.push([from, to]);
1165
+ function collectPairs(defaultObj, targetObj) {
1166
+ if (!defaultObj || !targetObj) return;
1167
+ for (const key of Object.keys(defaultObj)) {
1168
+ const defaultVal = defaultObj[key];
1169
+ const targetVal = targetObj[key];
1170
+ if (defaultVal && typeof defaultVal === 'object') {
1171
+ // Recurse into nested objects (produced by setNestedKey for dotted CSV keys)
1172
+ collectPairs(defaultVal, targetVal && typeof targetVal === 'object' ? targetVal : {});
1173
+ } else {
1174
+ const from = String(defaultVal ?? '').trim();
1175
+ const to = String(targetVal ?? '').trim();
1176
+ if (!from || from === to) continue;
1177
+ pairs.push([from, to]);
1178
+ }
1179
+ }
1171
1180
  }
1181
+ collectPairs(defaultLocaleData, targetLocaleData);
1182
+ // Sort longest-first so more specific strings are replaced before shorter substrings
1172
1183
  pairs.sort((a, b) => b[0].length - a[0].length);
1173
1184
  return pairs;
1174
1185
  }
@@ -1266,6 +1277,9 @@ function generateLocaleVariantHtml({
1266
1277
  html = stripRedundantImgSrcBindings(html);
1267
1278
  html = stripEmptyInlineMaskStyles(html);
1268
1279
  html = stripResolvedXIconDirectives(html);
1280
+ // markPrerenderedManifestComponents must run BEFORE stripPrerenderHydrateMarkers so it can
1281
+ // detect data-prerender-hydrate markers and skip components inside hydrate islands.
1282
+ html = markPrerenderedManifestComponents(html);
1269
1283
  html = stripPrerenderHydrateMarkers(html);
1270
1284
 
1271
1285
  const fileSegments = pathToFileSegments(pathSeg ? '/' + pathSeg : '/');
@@ -1290,7 +1304,6 @@ function generateLocaleVariantHtml({
1290
1304
  '</head>',
1291
1305
  `${canonicalHreflang}${injectOgLocale ? ogLocale : ''}${routeMeta}${baseMeta}<meta name="manifest:prerendered" content="1">\n<meta name="manifest:router-base-depth" content="${routeDepth}">\n</head>`
1292
1306
  );
1293
- html = markPrerenderedManifestComponents(html);
1294
1307
 
1295
1308
  return { html, utilityBlocks: pageUtilityBlocks };
1296
1309
  }
@@ -2295,6 +2308,9 @@ async function runPrerender(config) {
2295
2308
  html = stripRedundantImgSrcBindings(html);
2296
2309
  html = stripEmptyInlineMaskStyles(html);
2297
2310
  html = stripResolvedXIconDirectives(html);
2311
+ // markPrerenderedManifestComponents must run BEFORE stripPrerenderHydrateMarkers so it can
2312
+ // detect data-prerender-hydrate markers and skip components inside hydrate islands.
2313
+ html = markPrerenderedManifestComponents(html);
2298
2314
  html = stripPrerenderHydrateMarkers(html);
2299
2315
  html = rewriteHtmlAssetPaths(html, fileSegments.length);
2300
2316
  const liveBase = config.liveUrl.replace(/\/$/, '');
@@ -2314,7 +2330,6 @@ async function runPrerender(config) {
2314
2330
  '</head>',
2315
2331
  `${canonicalHreflang}${injectOgLocale ? ogLocale : ''}${routeMeta}${baseMeta}${prerenderedMeta}<meta name="manifest:router-base-depth" content="${routeDepth}">\n</head>`
2316
2332
  );
2317
- html = markPrerenderedManifestComponents(html);
2318
2333
  mkdirSync(outDir, { recursive: true });
2319
2334
  writeFileSync(outFile, html, 'utf8');
2320
2335
  pushDebug({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mnfst-render",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
4
4
  "description": "Render Manifest sites to static HTML for SEO",
5
5
  "type": "module",
6
6
  "bin": {