Skip to content

fix(search): bring Site search back with Back as the visitor left it - #1707

Merged
gregpriday merged 8 commits into
developfrom
feature/issue-1436-restore-the-published-search-query-and
Nov 28, 2026
Merged

gregpriday merged 8 commits into
developfrom
feature/issue-1436-restore-the-published-search-query-and

Conversation

@gregpriday

Copy link
Copy Markdown
Member

Same-tab Back from a Site search result now brings the search back as the visitor left it: the words in the box and the result list, ready to open another match.

Resolves #1436

Changes

  • New runtime search-history.js (shipped with every site): one SvelteKit snapshot() registration (keptSearches) holds every search on the page for each history entry, in memory and in the tab's session storage, never in the address. Each search is known by its region (header, footer, page), its name and label, and its order among searches alike, so a header search and a page search each get their own state back. A search that isn't showing when its entry returns never inherits another's words, and starts afresh when it shows.
  • Root layout calls snapshot(keptSearches). The helper itself imports nothing, so pages that render a search without the layout (the editor's component previews and the test harnesses) need nothing from $app/navigation.
  • Foundation site.search captures { query, sent, status, found } and restores finished results synchronously, with no new search. A search that hadn't finished (or had failed) runs again, an empty search shows its hint again, and a cleared search stays cleared. A ?q= search that is still in flight is dropped once the restore lands.
  • resources/packs/foundation/pack.json and resources/packs-dev/foundation-alt/pack.json are edited in place, with their digests refreshed in resources/packs.lock.json, following the earlier fix(foundation) commits.

Follow-up required: the same site.search change needs to land in siteorigin/builder-components. The lock still names the earlier builder-components commit, so a npm run build:packs from that checkout would revert this fix.

Testing

  • tests/unit/site-search-visitor.test.ts (headless Chromium): Back from a result restores the query, status and result link, and the list is present as soon as the search mounts. Also covered: a cleared search stays cleared, an empty search keeps its hint, two searches each get their own state (including words typed after the last search), a search hidden on return never takes another's state and starts afresh when it shows, and a persistent search comes back after its path reset. The $app/navigation stub models Kit's per-entry snapshot through session storage. The three Back cases fail on the old component.
  • tests/unit/generator.test.ts: the layout imports and calls snapshot(keptSearches) in the export and the preview, and the helper has no imports.
  • tests/unit/generated-site.ts: the no-navigation stub gains snapshot.
  • Impact set: 67 of 667 unit test files (10%), all green except container-queries-browser.test.ts › webkit "keeps a sticky query container stuck while its row scrolls by". That test fails on develop too (base-level).
  • npm run typecheck:changed green. The repo has no lint or format step.
  • Known limits: two searches with the same region, name and label are matched by their order, so if the first is missing on Back the second can take its state.
  • Not covered: a real SvelteKit client-side Back. The order Kit restores in (pathname reset first, then the snapshot after navigation settles) was checked against the 3.4.0 source, not driven. A long result list on a short page can still have its scroll offset clamped, because Kit restores scroll before the snapshot.

- a root-layout snapshot keeps every Site search on the page, told apart
  by its order, for each history entry
- each search hands back its box's words and the results of its last
  search, or searches again for one that had not finished
- refresh the Foundation pack digests
…helper import-free

- the layout hands keptSearches to SvelteKit's snapshot(), so pages that
  show a search need nothing from $app/navigation
- test the layout wiring and stub snapshot() in the generated-site harness
- a search not showing when its entry comes back never hands its words
  to another, and takes its own back once it shows
- test the kept list showing at once, an empty search, and a search that
  shows later
- drop the late claim, which could hand an entry's search to the next
  page or replace a restored search with the address's ?q=
- a search not showing as its entry returns starts afresh
@gregpriday
gregpriday force-pushed the feature/issue-1436-restore-the-published-search-query-and branch from 6a22d84 to f9e5515 Compare November 28, 2026 10:29
@gregpriday

Copy link
Copy Markdown
Member Author

CI on 46a6b5b failed in three files, none of them reached by this change:

  • tests/unit/inspector-anchor-field-browser.test.ts › "leaves it out of code that places no id, unless it still has an anchor to clear" and tests/unit/redirect-form-browser.test.ts › "names the draft at an old address, which takes it over once it is published (Assigning a kept public address to a draft removes its redirect #1363)" both fail the same way on origin/develop (3ccc6da) when run alone. They are base-level, and develop needs a fix for them.
  • tests/unit/inline-link.test.ts › "tells the editor when the field is left before its answer about a destination arrives" passes when run alone, a known flake.

The Site search tests (site-search-visitor, generator, committed-packs) pass on this head.

@gregpriday
gregpriday merged commit c75f340 into develop Nov 28, 2026
1 check passed
@gregpriday
gregpriday deleted the feature/issue-1436-restore-the-published-search-query-and branch November 28, 2026 11:21
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.

Restore the published search query and results when visitors go Back

1 participant