You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(demo-schema-react): restore searches with browser back and forward j:KIT-6460 - #8783
A shopper could not get back to a previous search: the demo never built or sent a restoreState snapshot. This uses the browser history, so back and forward step through the searches of a commerce-search surface. A reload is out of scope here: the demo starts a new server session, which has no search surface to restore into.
Changes
demo-schema-react
buildRestoreSnapshot builds the restoreState payload from a surface's state: the query summary's query, the pagination's page and page size, the applied sort, and each facet's active selection by field. That covers selected regular values, selected and custom numeric ranges, and the selected category path.
The CommerceSearch root records each search the surface settles on as a history entry. A snapshot is taken only once the session is free and the surface's state has changed, so one answer makes one entry, and the other surfaces don't add entries.
On back or forward to one of its entries, the surface dispatches restoreState once the session is free. The answer updates that entry in place, so the entries ahead of it stay reachable.
Dependencies
@coveo/thermidor-schema 1.0.0-beta.33 → 1.0.0-beta.34, which adds FacetRestore.path.
Validation
Demo tests pass (438), including new ones for the snapshot and the history hook. @coveo/thermidor tests pass (363) with beta.34. The demo typechecks.
Checked in the demo against the mock converse service: a search, then a category, then a sub-category made three entries. Back restored the category; forward sent restoreState with the path ["Surfing", "Surfboards"] and selected it again, with no new entry.
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
This PR includes no changesets
When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
An in-flight page or facet response can still call pushState after Back navigation, allowing an abandoned request to erase saved searches in the Forward history.
If a page or facet request is in flight when the shopper goes Back to an untagged entry or another surface's entry, this guard leaves its answer eligible for recording. Once the session is free, that answer can call pushState from the navigated-to entry and delete the saved searches in the Forward branch. Track navigation invalidation for ordinary requests as well as restores, and suppress abandoned answers without suppressing new searches started after navigation.
The reason will be displayed to describe this comment to others. Learn more.
The snapshot follows the schema contract, and deduplicating against the current entry keeps it to one entry per search. The two earlier Copilot fixes look right and are covered.
One thing before approving: the last Copilot finding (an in-flight action pushing after Back) is still open and holds up. Details inline.
Outside this PR: NumericFacetValue doesn't expose endInclusive, so the snapshot can't carry it, and the gateway's restoreState defaults it to true, while toggleSelect keeps the value the Commerce API returned. If the API returns exclusive ranges, a restore against the live gateway would include boundary products and might not match the listed value. Since this wasn't checked against a live gateway, worth confirming, and possibly exposing endInclusive in the schema or having the gateway match the restored range against its listed values.
Outside this PR: NumericFacetValue doesn't expose endInclusive, so the snapshot can't carry it, and the gateway's restoreState defaults it to true, while toggleSelect keeps the value the Commerce API returned. If the API returns exclusive ranges, a restore against the live gateway would include boundary products and might not match the listed value. Since this wasn't checked against a live gateway, worth confirming, and possibly exposing endInclusive in the schema or having the gateway match the restored range against its listed values.
thermidor-schema doesn't expose endInclusive on numeric facet values, so the snapshot has nothing to carry, and the demo only sends start and end. The only place it appears is the optional field on NumericRangeRestore, which the gateway defaults to true. Whether that default matches the ranges the Commerce API returns is a gateway question, outside these PRs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Jira
https://coveord.atlassian.net/browse/KIT-6460
Motivation
A shopper could not get back to a previous search: the demo never built or sent a
restoreStatesnapshot. This uses the browser history, so back and forward step through the searches of a commerce-search surface. A reload is out of scope here: the demo starts a new server session, which has no search surface to restore into.Changes
demo-schema-reactbuildRestoreSnapshotbuilds therestoreStatepayload from a surface's state: the query summary's query, the pagination's page and page size, the applied sort, and each facet's active selection by field. That covers selected regular values, selected and custom numeric ranges, and the selected category path.CommerceSearchroot records each search the surface settles on as a history entry. A snapshot is taken only once the session is free and the surface's state has changed, so one answer makes one entry, and the other surfaces don't add entries.restoreStateonce the session is free. The answer updates that entry in place, so the entries ahead of it stay reachable.Dependencies
@coveo/thermidor-schema1.0.0-beta.33 → 1.0.0-beta.34, which addsFacetRestore.path.Validation
@coveo/thermidortests pass (363) with beta.34. The demo typechecks.restoreStatewith the path["Surfing", "Surfboards"]and selected it again, with no new entry.🤖 Generated with Claude Code