mnfst-render 0.1.3 → 0.1.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.
Files changed (2) hide show
  1. package/manifest.render.mjs +15 -13
  2. package/package.json +1 -1
@@ -953,6 +953,20 @@ async function runPrerender(config) {
953
953
  await page.evaluate(() => {
954
954
  const loopVarRegex = /^\s*(?:\(\s*([A-Za-z_$][\w$]*)(?:\s*,\s*([A-Za-z_$][\w$]*))?\s*\)|([A-Za-z_$][\w$]*))\s+in\s+/;
955
955
  const bindingAttrRegex = /^(?:x-bind:|:|x-text|x-html|x-show|x-if|x-model|x-effect|x-on:|@)/;
956
+ const hasVar = (expr, varName) => varName && new RegExp(`\\b${varName}\\b`).test(expr || '');
957
+ const elementReferencesLoopScope = (el, itemVar, indexVar) => {
958
+ if (!el) return false;
959
+ const nodes = [el, ...Array.from(el.querySelectorAll('*'))];
960
+ for (const node of nodes) {
961
+ const attrs = node.attributes ? Array.from(node.attributes) : [];
962
+ for (const attr of attrs) {
963
+ if (!bindingAttrRegex.test(attr.name)) continue;
964
+ const expr = attr.value || '';
965
+ if (hasVar(expr, itemVar) || hasVar(expr, indexVar)) return true;
966
+ }
967
+ }
968
+ return false;
969
+ };
956
970
 
957
971
  document.querySelectorAll('template[x-for]').forEach((tpl) => {
958
972
  const xFor = (tpl.getAttribute('x-for') || '').trim();
@@ -970,19 +984,7 @@ async function runPrerender(config) {
970
984
  const sameTag = next.tagName === tag;
971
985
  if (!sameTag) break;
972
986
 
973
- let referencesLoopScope = false;
974
- const attrNodes = next.attributes ? Array.from(next.attributes) : [];
975
- for (const attr of attrNodes) {
976
- if (!bindingAttrRegex.test(attr.name)) continue;
977
- const expr = attr.value || '';
978
- if (
979
- (itemVar && new RegExp(`\\b${itemVar}\\b`).test(expr)) ||
980
- (indexVar && new RegExp(`\\b${indexVar}\\b`).test(expr))
981
- ) {
982
- referencesLoopScope = true;
983
- break;
984
- }
985
- }
987
+ const referencesLoopScope = elementReferencesLoopScope(next, itemVar, indexVar);
986
988
 
987
989
  const toRemove = next;
988
990
  next = next.nextElementSibling;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mnfst-render",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Render Manifest sites to static HTML for SEO",
5
5
  "type": "module",
6
6
  "bin": {