Skip to content

fix: fire on-enter for the default route at startup (#81) - #87

Merged
geoffjay merged 1 commit into
mainfrom
fix/issue-81-initial-route-on-enter
Aug 1, 2026
Merged

fix: fire on-enter for the default route at startup (#81)#87
geoffjay merged 1 commit into
mainfrom
fix/issue-81-initial-route-on-enter

Conversation

@geoffjay

@geoffjay geoffjay commented Aug 1, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes #81. A <route>'s on-enter hook did not fire for the default route when a <router> first mounted at startup — it only fired on subsequent navigations, making on-enter unusable for "run something when the initial page is shown."

Root cause: the initial path is seeded through lazy initialization (router_current_path, called from the render pass) without a path change, so apply_one_navigation — which fires on-leave/on-enter only when old_path != new_path — never sees the initial mount and skips its on-enter.

Approach

Firing from the render pass directly would risk a re-entrant deadlock (call_handler holds the extension_manager write lock), so this mirrors the existing deferred-navigation design:

  • Added a pending_initial_enters queue on NemoRuntime.
  • When router_current_path first seeds a router to its default (or --route override), it enqueues the router id and pings data_notify (once — later renders find existing state).
  • New fire_pending_initial_enters() drains the queue, projects the route's path+params, and fires its on-enter once, outside the extension lock.
  • The App poll loop calls it right after apply_pending_navigations() and before the data-update pass, so the projection propagates in the same wake.

Result: the default route's on-enter fires at startup, consistent with later navigations; each route's on-enter fires exactly once when it becomes active.

Testing

  • New regression test test_initial_default_route_fires_on_enter (fires with no prior navigation; fires exactly once).
  • Existing navigation and --route override tests still pass; clippy clean.

Docs

Updated docs/knowledgebase/patterns/routing.md and added a log.md entry.

🤖 Generated with Claude Code

A `<route>`'s `on-enter` hook did not fire for the default route when a
`<router>` first mounted; it only fired on subsequent navigations. The
initial path is seeded through lazy initialization (`router_current_path`,
from the render pass) without a path *change*, so `apply_one_navigation` —
which fires hooks only when `old_path != new_path` — never saw the initial
mount and skipped its `on-enter`.

Mirror the existing deferred-navigation design: when `router_current_path`
first seeds a router to its `default` (or `--route` override), enqueue the
router id in a new `pending_initial_enters` queue and ping `data_notify`.
The App poll loop drains it via `fire_pending_initial_enters()` right after
`apply_pending_navigations()` and before the data-update pass, projecting
the route and firing its `on-enter` once, outside the extension lock (the
same re-entrancy-safe apply point as navigation hooks). Firing is deferred
out of the render pass because `call_handler` holds the extension write
lock.

Adds regression test `test_initial_default_route_fires_on_enter`; updates
the routing KB doc and log.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@codecov

codecov Bot commented Aug 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 56.59%. Comparing base (82b766c) to head (8721f07).

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #87   +/-   ##
=======================================
  Coverage   56.59%   56.59%           
=======================================
  Files          78       78           
  Lines        6866     6866           
=======================================
  Hits         3886     3886           
  Misses       2980     2980           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@geoffjay
geoffjay merged commit aa91500 into main Aug 1, 2026
7 checks passed
@geoffjay
geoffjay deleted the fix/issue-81-initial-route-on-enter branch August 1, 2026 05:37
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.

Route on-enter does not fire for the default route at startup

1 participant