mnfst 0.5.26 → 0.5.28

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.
@@ -2315,32 +2315,38 @@ function getLoadingBranchSafe() {
2315
2315
  return cachedLoadingBranchSafe;
2316
2316
  }
2317
2317
 
2318
- // Chainable loading branch: return self for string keys, callable for $route. Used for
2319
- // json/yaml/etc so $x.json.products.$route('path').name and deep paths don't throw.
2320
- let cachedLoadingBranch = null;
2321
- function getLoadingBranch() {
2322
- if (cachedLoadingBranch) return cachedLoadingBranch;
2323
- const returnSelf = function () { return cachedLoadingBranch; };
2318
+ // Max depth for loading placeholder chain; beyond this, string keys return '' to avoid stack overflow.
2319
+ const MAX_LOADING_BRANCH_DEPTH = 10;
2320
+
2321
+ const loadingBranchByDepth = Object.create(null);
2322
+ function getLoadingBranch(depth) {
2323
+ const d = depth == null ? 0 : Math.min(Math.max(0, depth), MAX_LOADING_BRANCH_DEPTH);
2324
+ if (loadingBranchByDepth[d]) return loadingBranchByDepth[d];
2324
2325
  const emptyStr = function () { return ''; };
2325
- cachedLoadingBranch = new Proxy(Object.create(null), {
2326
+ const nextDepth = d + 1;
2327
+ const getReturnForStringKey = () =>
2328
+ nextDepth <= MAX_LOADING_BRANCH_DEPTH ? getLoadingBranch(nextDepth) : '';
2329
+ loadingBranchByDepth[d] = new Proxy(Object.create(null), {
2326
2330
  get(_, key) {
2327
2331
  if (key === Symbol.toPrimitive || key === 'valueOf' || key === 'toString') return emptyStr;
2328
2332
  if (key === 'then' || key === 'catch' || key === 'finally') return undefined;
2329
2333
  if (key === Symbol.iterator) return function* () { };
2330
- if (key === '$route' || key === '$search' || key === '$query') return returnSelf;
2334
+ if (key === '$route' || key === '$search' || key === '$query') {
2335
+ return function () { return getLoadingBranch(nextDepth <= MAX_LOADING_BRANCH_DEPTH ? nextDepth : MAX_LOADING_BRANCH_DEPTH); };
2336
+ }
2331
2337
  if (key === 'length') return 0;
2332
- if (typeof key === 'string') return cachedLoadingBranch;
2333
- return undefined;
2338
+ if (typeof key === 'string') return getReturnForStringKey();
2339
+ if (typeof key === 'symbol') return undefined;
2340
+ return getLoadingBranch(MAX_LOADING_BRANCH_DEPTH);
2334
2341
  },
2335
2342
  has() { return true; }
2336
2343
  });
2337
- return cachedLoadingBranch;
2344
+ return loadingBranchByDepth[d];
2338
2345
  }
2339
2346
 
2340
2347
  // Create a simple fallback object that returns empty strings for all properties.
2341
- // When propForPlaceholder === 'content', nested data keys use getLoadingBranchSafe() (primitives only)
2342
- // so Alpine never gets a chainable proxy and $x.content.theme.light doesn't stack overflow.
2343
- // For other props (json, yaml, etc.) use getLoadingBranch() (chainable) so $route and deep paths work.
2348
+ // Nested data keys use getLoadingBranch() (chainable) so $route, $search, $query and deep paths
2349
+ // don't throw while loading (e.g. $x.content.legal.$route('path')).
2344
2350
  function createSimpleFallback(propForPlaceholder) {
2345
2351
  const fallback = Object.create(null);
2346
2352
 
@@ -2496,11 +2502,11 @@ function createSimpleFallback(propForPlaceholder) {
2496
2502
  }
2497
2503
  }
2498
2504
 
2499
- // For string keys that look like data: use safe placeholder for 'content' (primitives only,
2500
- // no re-entry/stack overflow); use chainable placeholder for other props ($route, deep paths).
2505
+ // For string keys that look like data: use chainable placeholder so nested arrays (e.g. content.legal)
2506
+ // have $route/$search/$query and expressions like $x.content.legal.$route('path') don't throw while loading.
2501
2507
  if (typeof key === 'string' && key.length > 0 && key.length < 64 &&
2502
2508
  !key.startsWith('$') && key !== 'length') {
2503
- return propForPlaceholder === 'content' ? getLoadingBranchSafe() : getLoadingBranch();
2509
+ return getLoadingBranch();
2504
2510
  }
2505
2511
 
2506
2512
  // For any other key, return chaining fallback — never return the loading proxy itself.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mnfst",
3
- "version": "0.5.26",
3
+ "version": "0.5.28",
4
4
  "private": false,
5
5
  "workspaces": [
6
6
  "templates/starter"