Skip to content

[6.x] Fix NavBuilder crash when nav item has an unresolved children Closure#14523

Merged
jasonvarga merged 1 commit intostatamic:6.xfrom
v-Woody:fix/nav-builder-unresolved-children-closure
Apr 21, 2026
Merged

[6.x] Fix NavBuilder crash when nav item has an unresolved children Closure#14523
jasonvarga merged 1 commit intostatamic:6.xfrom
v-Woody:fix/nav-builder-unresolved-children-closure

Conversation

@v-Woody
Copy link
Copy Markdown
Contributor

@v-Woody v-Woody commented Apr 21, 2026

Description

NavBuilder::ensureUrlCachesAreUpToDate() crashes with Undefined property: Closure::$map when a nav item has a children closure that hasn't been resolved yet.

Root Cause

resolveChildrenClosures() only resolves children for active items ($item->isActive()). However, ensureUrlCachesAreUpToDate() processes all items in $itemsWithChildrenClosures (filtered by isActive()) and calls $item->children()?->map->url() on them.

If an item's children closure wasn't resolved during resolveChildrenClosures() (e.g. it wasn't active at that point but is now active), $item->children() returns the raw Closure. The null-safe operator ?-> doesn't help since a Closure is not null, so accessing ->map on it throws Undefined property: Closure::$map.

Fix

Call resolveChildren() on each item before accessing children() in ensureUrlCachesAreUpToDate(). resolveChildren() is idempotent — if children are already resolved it returns early.

// Before
->mapWithKeys(fn ($item) => [$item->id() => $item->children()?->map->url()->all() ?? []])

// After
->mapWithKeys(fn ($item) => [$item->id() => $item->resolveChildren()->children()?->map->url()->all() ?? []])

Stack Trace

ErrorException: Undefined property: Closure::$map
  at vendor/statamic/cms/src/CP/Navigation/NavBuilder.php:1001

@v-Woody v-Woody changed the title Fix NavBuilder crash when nav item has an unresolved children Closure [6.x] Fix NavBuilder crash when nav item has an unresolved children Closure Apr 21, 2026
@jasonvarga jasonvarga merged commit d9cf66e into statamic:6.x Apr 21, 2026
18 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants