fix(search): keep a trailing space when the trimmed q echo lands after the debounce (#1474)

* fix(search): keep a trailing space when the trimmed q echo lands after the debounce

The #1432 guard only held while a debounce was still pending. Once it
fired, the router echo of our own trimmed q (replaceUrl navigation)
reset the one-way-bound search box to the trimmed term, deleting the
just-typed trailing space — typing "Bein Sports" collapsed into
"BeinSports".

Applied terms are now always trimmed at the apply choke point (URL sync
and portal stores only ever act on the trimmed form anyway), so the
echoed q compares directly, and the echo guard no longer requires a
pending debounce. Back/forward stays authoritative via the untouched
imperative-trigger check.

Residual part of #1338.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* fix(search): make the trimmed-applied-term invariant structural and update the shell contract doc

Review follow-ups on the echo-guard widening:

- setSearchState now trims too, so URL-sourced terms (deep links with
  ?q=Bein%20, actor/discover prefills passing raw provider titles) cannot
  put an untrimmed term into appliedSearchQuery — previously that path
  failed the echo guard's equality check, snapped the box, and dispatched
  the portal search twice. Regression spec added.
- docs/architecture/workspace-shell.md item 8 updated: the applied-term
  echo is now always ignored, not only while input is still debouncing.
- The facade spec's router mock exposes a mutable navigation trigger so
  facade-level tests can exercise the popstate branch.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* fix(search): compare the echoed q in trimmed form in the echo guard

Adoption trims, so a same-page imperative navigation still carrying a
not-yet-rewritten untrimmed q adopts to exactly the applied state —
syncing it could only cancel a pending debounce. Comparing the trimmed
form closes that window.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: 4gray <fourgray@proton.me>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
authored and GitHub committed 2026-08-23 11:47:43 +02:00
1 parent 9494643a8d
commit 7efb8c4f66
5 files changed
+117 -16

No files matched your search

+12 -6
View File
@@ -165,12 +165,18 @@ Search is shell-owned and route-aware:
8. The URL is authoritative for the search box only when it carries search
intent. `WorkspaceShellSearchSyncService` re-reads `q` on every
`NavigationEnd`, but an **app-initiated** navigation that stays on the same
page and carries the term already applied is ignored while input is still
debouncing — otherwise a page writing an unrelated query param (a downloads
filter chip, a refresh bump) or the router echoing back our own `q` would
cancel the pending debounce and reset the box, eating everything typed
since. Pages are free to write their own query params while the user types;
they must not assume the shell will re-apply the search afterwards.
page and carries the term already applied is always ignored — whether or
not a debounce is still pending. Otherwise a page writing an unrelated
query param (a downloads filter chip, a refresh bump) or the router echoing
back our own trimmed `q` would reset the box to the applied term, eating
everything typed since: the whole word while the first keystroke is still
debouncing, or a just-typed trailing space once the debounce has fired
("Bein " would snap to "Bein" and typing on would yield "BeinSports").
Applied terms are always stored trimmed (`applySearchQuery` and
`setSearchState` both trim), so the echoed `q` compares directly; the box
keeps exactly what the user typed. Pages are free to write their own query
params while the user types; they must not assume the shell will re-apply
the search afterwards.
9. Browser history overrides that guard. The exemption is keyed on
`Navigation.trigger === 'imperative'`, so back/forward always re-applies
what the history entry carries, even mid-typing.