Skip to content

Fix duplicate clientNavigated inspector events on successful SetUrl - #32081

Merged
alii merged 2 commits into
mainfrom
farm/cf91129e/fix-duplicate-client-navigated
Jun 11, 2026
Merged

alii merged 2 commits into
mainfrom
farm/cf91129e/fix-duplicate-client-navigated

Conversation

@robobun

@robobun robobun commented Jun 10, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #32080

Problem

The HMR socket's SetUrl handler notified the inspector's BunFrontendDevServer.clientNavigated twice for a successful navigation to a new route bundle: once inline right after route_to_bundle_index_slow, and again via notify_inspector_client_navigation after SetUrlResponse was sent. Both events carried identical payloads. One SetUrl message over /_bun/hmr produced:

{"serverId":0,"connectionId":0,"url":"/second","routeBundleId":1}
{"serverId":0,"connectionId":0,"url":"/second","routeBundleId":1}

The failed-lookup and same-route paths correctly sent a single event. Both calls date back to the original inspector support in 570e6b7 (#19340); the Rust port reproduced the behavior faithfully.

Fix

Remove the trailing notify_inspector_client_navigation call in the SetUrl arm of HmrSocket::on_message. The inline notify already fires exactly once for every SetUrl, with the correct routeBundleId on all three paths (new route, same route, failed lookup with routeBundleId absent). The helper had no remaining callers, so it is deleted.

Note: this issue surfaced during review of #32076, which has since merged; this branch is rebased on top of it.

Verification

New test in test/cli/inspect/BunFrontendDevServer.test.ts sends one SetUrl for a matched route followed by one for an unknown route (an ordering sentinel, since inspector events are emitted synchronously and delivered in order), then asserts exactly one clientNavigated per message, including that the failed lookup still reports a single event with no routeBundleId.

On the unfixed build the test fails with two identical /second events; with the fix the whole file passes (6 pass, 2 todo).

@robobun

robobun commented Jun 10, 2026 •

Copy link
Copy Markdown
Collaborator Author
Updated 6:02 PM PT - Jun 10th, 2026

❌ @robobun, your commit b63f4bd has 1 failures in Build #61837 (All Failures):


🧪   To try this PR locally:

bunx bun-pr 32081

That installs a local version of the PR into your bun-32081 executable, so you can run:

bun-32081 --bun

@coderabbitai

coderabbitai Bot commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The SetUrl handler now notifies the inspector inline (constructs pattern and maps route bundle index) and the duplicate helper was removed. A new test asserts the dev server emits exactly one BunFrontendDevServer.clientNavigated event per SetUrl message.

Changes

Duplicate inspector event fix

Layer / File(s) Summary
Remove duplicate notifications in SetUrl handler
src/runtime/bake/DevServer/HmrSocket.rs
The SetUrl handler inlines inspector-client notification logic (pattern creation and route index mapping) and removes the notify_inspector_client_navigation helper method, eliminating the second duplicate event.
Test single clientNavigated event per SetUrl
test/cli/inspect/BunFrontendDevServer.test.ts
New test validates that the dev server emits exactly one clientNavigated event per SetUrl WebSocket message, driving two sequential navigations and asserting correct event count, URLs, and routeBundleId presence/absence.
  • Possibly related PRs:
    • oven-sh/bun#32076: Modifies the same HmrSocket inspector navigation handling and retrieves the agent via the new DevServer::inspector() API.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: removing duplicate clientNavigated inspector events in the SetUrl handler.
Description check ✅ Passed The description covers the problem, fix, and verification with sufficient detail; however, it lacks explicit mapping to the template structure (e.g., 'What does this PR do?' and 'How did you verify your code works?' sections).
Linked Issues check ✅ Passed The code changes directly address all objectives from #32080: the duplicate notify_inspector_client_navigation call is removed, the helper is deleted, inline notification works correctly for all paths, and a new test verifies exactly one event per SetUrl.
Out of Scope Changes check ✅ Passed All changes are directly scoped to #32080: removing duplicate notifications from HmrSocket.rs, deleting an unused helper, and adding a test to verify the fix.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@test/cli/inspect/BunFrontendDevServer.test.ts`:
- Line 518: The fetch of serverUrl.href that consumes the response blob
(invocation using fetch(serverUrl.href).then(r => r.blob())) is unused and
unclear; either remove this no-op fetch call or, if it is required to prime the
dev server or register routes, add an inline comment explaining its purpose
(e.g., "prime dev server to ensure routes are registered before assertions")
next to the fetch so future readers know why it is present; look for the same
pattern around serverUrl usage in the BunFrontendDevServer.test test helper and
update those occurrences consistently.
- Around line 521-548: The test currently closes the WebSocket (ws.close()) only
after assertions, which can leave the socket open if an assertion fails; wrap
the interaction and assertions that use ws in a try/finally so ws.close() is
invoked regardless of test outcome — i.e., after creating ws via
createHMRClient() and setting up connectedEventPromise, navigated array,
Promise.withResolvers, session.addEventListener and ws event listeners,
immediately enter a try block for sending messages and awaiting
sawSentinelNavigation and performing expect(navigated).toEqual(...), and put
ws.close() in the finally block to ensure cleanup even on failure.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: b4e539b6-3546-4ed9-bfca-125ccd006bf5

📥 Commits

Reviewing files that changed from the base of the PR and between 8df5916 and a2010a3.

📒 Files selected for processing (2)
  • src/runtime/bake/DevServer/HmrSocket.rs
  • test/cli/inspect/BunFrontendDevServer.test.ts
💤 Files with no reviewable changes (1)
  • src/runtime/bake/DevServer/HmrSocket.rs

@robobun
robobun force-pushed the farm/cf91129e/fix-duplicate-client-navigated branch from 9fe5653 to b63f4bd Compare June 10, 2026 23:19

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@test/cli/inspect/BunFrontendDevServer.test.ts`:
- Line 520: The test uses a fetch chain with .then(r => r.blob()) (in
BunFrontendDevServer.test.ts where serverUrl.href is used); change it to use
async/await by replacing await fetch(serverUrl.href).then(r => r.blob()) with
await (await fetch(serverUrl.href)).blob(); update all similar occurrences in
the file so the code follows the async/await pattern and avoids .then chains.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 58e8e97e-e61e-40e7-8cd8-c167df5d1a77

📥 Commits

Reviewing files that changed from the base of the PR and between 3bb7281 and b63f4bd.

📒 Files selected for processing (2)
  • src/runtime/bake/DevServer/HmrSocket.rs
  • test/cli/inspect/BunFrontendDevServer.test.ts

@alii
alii enabled auto-merge (squash) June 11, 2026 00:38
@alii
alii merged commit f8723b1 into main Jun 11, 2026
4 checks passed
@alii
alii deleted the farm/cf91129e/fix-duplicate-client-navigated branch June 11, 2026 01:02
robobun added a commit that referenced this pull request Jun 11, 2026
Restore src/runtime/bake/DevServer/HmrSocket.rs and
test/cli/inspect/BunFrontendDevServer.test.ts to their state on main.
The branch accidentally re-added the duplicate clientNavigated inspector
notify and deleted the guard test, both from #32081.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dev server sends duplicate clientNavigated inspector events on successful SetUrl

2 participants