@uniflowed/router 0.0.0-alpha.27 → 0.0.0-alpha.29

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.
@@ -57,6 +57,7 @@ import {
57
57
  PAYLOAD_ROW_ATTRIBUTE,
58
58
  PayloadRowError,
59
59
  PayloadValueError,
60
+ payloadRowId,
60
61
  parseRowMessage,
61
62
  } from "./payload.js";
62
63
 
@@ -149,8 +150,8 @@ export function createPayloadReader(
149
150
  if (attribute == null) {
150
151
  return;
151
152
  }
152
- const id = Number.parseInt(attribute, 10);
153
- if (!Number.isSafeInteger(id)) {
153
+ const id = payloadRowId(attribute);
154
+ if (id == null) {
154
155
  return;
155
156
  }
156
157
  const slot = slots.get(id);
@@ -580,6 +580,19 @@ function decodeReference(value: string, path: string, resolve: RowResolver): mix
580
580
  return resolve(id);
581
581
  }
582
582
 
583
+ /**
584
+ * The row id carried by a streamed row element, or `null` when the attribute
585
+ * is not one.
586
+ *
587
+ * This is the same grammar as the `$P<n>` reference without the `$P` tag:
588
+ * digits only, in range. The browser reads row elements from a live document,
589
+ * so accepting `Number.parseInt`'s looser spellings would let `1x` satisfy the
590
+ * row the model named as `$P1`.
591
+ */
592
+ export function payloadRowId(value: string): number | null {
593
+ return parsePayloadRowId(value);
594
+ }
595
+
583
596
  /**
584
597
  * The row a reference names, or `null` when the string is not one.
585
598
  *
@@ -591,7 +604,10 @@ function rowId(value: string): number | null {
591
604
  if (!value.startsWith(REFERENCE_PREFIX + ROW_TAG)) {
592
605
  return null;
593
606
  }
594
- const digits = value.slice(2);
607
+ return parsePayloadRowId(value.slice(2));
608
+ }
609
+
610
+ function parsePayloadRowId(digits: string): number | null {
595
611
  if (digits.length === 0 || digits.length > 3) {
596
612
  return null;
597
613
  }
@@ -1227,7 +1227,12 @@ async function resolveRoute(
1227
1227
  // are: a slot is matched against the URL and depends on nothing the loader
1228
1228
  // produces, so the second match and its imports overlap the first page's
1229
1229
  // loader rather than following it.
1230
- const slots = resolveSlots(matched.route.slots ?? [], pathname, matched.route.layouts.length);
1230
+ const slots = resolveSlots(
1231
+ matched.route.slots ?? [],
1232
+ pathname,
1233
+ matched.route.layouts.length,
1234
+ matched.params,
1235
+ );
1231
1236
 
1232
1237
  // The loader, run here and awaited below — or not awaited at all.
1233
1238
  //
@@ -1311,17 +1316,21 @@ async function resolveSlots(
1311
1316
  records: $ReadOnlyArray<SlotRecord>,
1312
1317
  pathname: string,
1313
1318
  layoutCount: number,
1319
+ fallbackParams: RouteParams,
1314
1320
  ): Promise<$ReadOnlyArray<ResolvedSlot>> {
1315
1321
  if (records.length === 0) {
1316
1322
  return [];
1317
1323
  }
1318
- return Promise.all(records.map((record) => resolveSlot(record, pathname, layoutCount)));
1324
+ return Promise.all(
1325
+ records.map((record) => resolveSlot(record, pathname, layoutCount, fallbackParams)),
1326
+ );
1319
1327
  }
1320
1328
 
1321
1329
  async function resolveSlot(
1322
1330
  record: SlotRecord,
1323
1331
  pathname: string,
1324
1332
  layoutCount: number,
1333
+ fallbackParams: RouteParams,
1325
1334
  ): Promise<ResolvedSlot> {
1326
1335
  // Clamped exactly as a template's `above` is, and for the same reason: a
1327
1336
  // hand-written table, or a `(group)` between the layout and the route, can
@@ -1331,7 +1340,7 @@ async function resolveSlot(
1331
1340
  name: record.name,
1332
1341
  above,
1333
1342
  page: null,
1334
- params: {},
1343
+ params: fallbackParams,
1335
1344
  layouts: [],
1336
1345
  slots: [],
1337
1346
  };
@@ -1373,7 +1382,7 @@ async function resolveSlot(
1373
1382
  layouts: loaded,
1374
1383
  // The slot's own layouts are what a nested slot is measured against, so
1375
1384
  // the count handed down is this slot's rather than the route's.
1376
- slots: await resolveSlots(route.slots, pathname, loaded.length),
1385
+ slots: await resolveSlots(route.slots, pathname, loaded.length, matched.params),
1377
1386
  };
1378
1387
  }
1379
1388
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniflowed/router",
3
- "version": "0.0.0-alpha.27",
3
+ "version": "0.0.0-alpha.29",
4
4
  "description": "The file-system router for Flow React applications: matching, layouts, loaders, navigation, server rendering and hydration.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -34,7 +34,7 @@
34
34
  "react-dom": ">=19"
35
35
  },
36
36
  "dependencies": {
37
- "@uniflowed/hooks": "0.0.0-alpha.27",
38
- "@uniflowed/server": "0.0.0-alpha.27"
37
+ "@uniflowed/hooks": "0.0.0-alpha.29",
38
+ "@uniflowed/server": "0.0.0-alpha.29"
39
39
  }
40
40
  }