Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/fix-saved-search-client-side-navigation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@hyperdx/app': patch
---

Saving a search no longer reloads the page: the new saved search is opened with
a client-side navigation, which also fixes the 404 this caused on the static
ClickStack build.
2 changes: 1 addition & 1 deletion packages/app/AGENTS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!-- BEGIN:nextjs-agent-rules -->

# This is NOT the Next.js you know
## This is NOT the Next.js you know

This version has breaking changes — APIs, conventions, and file structure may all differ from your training data. Read the relevant guide in `node_modules/next/dist/docs/` (resolved from this file's directory; in monorepos the `next` package may not be visible from the repo root) before writing any code. Heed deprecation notices.

Expand Down
55 changes: 38 additions & 17 deletions packages/app/src/DBSearchPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -465,12 +465,14 @@ function SaveSearchModalComponent({
searchedConfig,
opened,
onClose,
onCreate,
isUpdate,
savedSearchId,
}: {
searchedConfig: SearchConfig;
opened: boolean;
onClose: () => void;
onCreate: (savedSearchId: string) => Promise<void>;
isUpdate: boolean;
savedSearchId: string | undefined | null;
}) {
Expand Down Expand Up @@ -576,18 +578,8 @@ function SaveSearchModalComponent({
tags: tags,
});

// useQueryStates can restore the previous search URL during a
// client-side transition. Reload the saved-search route instead so
// the newly created search hydrates from its stored configuration,
// rather than stale query state from the previous search. Preserve
// only the independent time range, which is not saved-search config.
window.location.assign(
buildSavedSearchNavigationUrl(
router.basePath,
savedSearch.id,
window.location.search,
),
);
await onCreate(savedSearch.id);
onClose();

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.

🔵 minor — After a successful create, the modal closes without resetting the form, so the typed name is still there next time it opens

Call closeAndReset() instead of onClose() after await onCreate(...). Before this PR, the full page reload threw away the modal's react-hook-form state. Now SaveSearchModal stays mounted, and in create mode useForm gets no values. So if the user clicks "Save as new" on the new saved-search page (onClickSaveAsNew → setSaveSearchModalState('create')), the name field is pre-filled with the previous search's name.

Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond

} catch (error) {
console.error('Error creating saved search:', error);
notifications.show({
Expand Down Expand Up @@ -926,8 +918,14 @@ const queryStateMap = {
orderBy: parseAsStringEncoded,
};

/**
* Route for a newly created saved search. The saved-search config params are
* dropped so the page hydrates from the stored configuration; only the time
* range is carried over, since it is not part of a saved search.
*
* Returned without `router.basePath` — `router.push` prepends it.
*/
export function buildSavedSearchNavigationUrl(
basePath: string,
savedSearchId: string,
currentSearch: string,
) {
Expand All @@ -940,15 +938,15 @@ export function buildSavedSearchNavigationUrl(
timeRangeParams.set('from', from);
timeRangeParams.set('to', to);

// An explicit absolute range must remain in range mode after the saved
// search reload; otherwise the default live-tail mode can take over.
// An explicit absolute range must stay in range mode on the saved search;
// otherwise the default live-tail mode can take over.
if (currentParams.get('isLive') === 'false') {
timeRangeParams.set('isLive', 'false');
}
}

const timeRangeSearch = timeRangeParams.toString();
return `${basePath}/search/${savedSearchId}${
return `/search/${savedSearchId}${
timeRangeSearch ? `?${timeRangeSearch}` : ''
}`;
}
Expand Down Expand Up @@ -1769,7 +1767,14 @@ function DBSearchPageContent() {
interval,
refreshFrequency,
onTimeRangeSelect,
pause: isAnyQueryFetching || !queryReady || !isTabVisible,
// The save modal captures the search as it stands, so refreshing the time
// range underneath it is both surprising and a source of query-string
// writes that would race the navigation to the new saved search.
pause:
isAnyQueryFetching ||
!queryReady ||
!isTabVisible ||
saveSearchModalState != null,
});

// This ensures we only render this conditionally on the client
Expand Down Expand Up @@ -2246,6 +2251,21 @@ function DBSearchPageContent() {
[setSaveSearchModalState],
);

const onSavedSearchCreated = useCallback(
async (newSavedSearchId: string) => {
// nuqs batches query-string writes and flushes them onto whatever path
// the router reports at flush time, which during a client-side
// transition is still the old one. Draining the queue first keeps a
// pending write (live tail refreshes the time range on a timer) from
// landing after the push and sending us back to /search.
await setSearchedConfig({});
router.push(
buildSavedSearchNavigationUrl(newSavedSearchId, window.location.search),
);
},
[setSearchedConfig],
);

const onModelFormExpandClose = useCallback(() => {
setModelFormExpanded(false);
}, [setModelFormExpanded]);
Expand Down Expand Up @@ -2649,6 +2669,7 @@ function DBSearchPageContent() {
<SaveSearchModal
opened={saveSearchModalState != null}
onClose={clearSaveSearchModalState}
onCreate={onSavedSearchCreated}
searchedConfig={searchedConfig}
isUpdate={saveSearchModalState === 'update'}
savedSearchId={savedSearchId}
Expand Down
Loading
Loading