Skip to content

Commit 4596dbe

Browse files
committed
fix(navigation): account for race conditions in developer's code
1 parent 400aa54 commit 4596dbe

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/navigation/url-serializer.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -364,11 +364,19 @@ export function hydrateSegmentsWithNav(app: App, dehydratedSegmentPairs: Dehydra
364364
for (const dehydratedSegment of dehydratedSegmentPairs[i].segments) {
365365
if (navs.length === 1) {
366366
segments.push(hydrateSegment(dehydratedSegment, navs[0]));
367-
} else if (navs.length > 1 || navs.length <= 0) {
367+
navs = navs[0].getActiveChildNavs();
368+
} else if (navs.length > 1) {
369+
// this is almost certainly an async race condition bug in userland
370+
// if you're in this state, it would be nice to just bail here
371+
// but alas we must perservere and handle the issue
372+
// the simple solution is to just use the last child
373+
// because that is probably what the user wants anyway
374+
// remember, do not harm, even if it makes our shizzle ugly
375+
segments.push(hydrateSegment(dehydratedSegment, navs[navs.length - 1]));
376+
navs = navs[navs.length - 1].getActiveChildNavs();
377+
} else {
368378
break;
369-
// throw new Error('Invalid URL - could not determine which nav to use');
370379
}
371-
navs = navs[0].getActiveChildNavs();
372380
}
373381
}
374382
return segments;
@@ -514,7 +522,7 @@ export function getSegmentsFromUrlPieces(urlSections: string[], navLink: NavLink
514522
export function hydrateSegment(segment: DehydratedSegment, nav: NavigationContainer) {
515523
const hydratedSegment = Object.assign({}, segment) as NavSegment;
516524
hydratedSegment.type = nav.getType();
517-
hydratedSegment.navId = nav.id;
525+
hydratedSegment.navId = nav.name || nav.id;
518526
// secondaryId is set on an empty dehydrated segment in the case of tabs to identify which tab is selected
519527
hydratedSegment.secondaryId = segment.secondaryId;
520528
return hydratedSegment;

0 commit comments

Comments
 (0)