Skip to content

feat: preserve user's language preference in search page#1775

Open
akshat1074 wants to merge 3 commits intohyperdxio:mainfrom
akshat1074:feat/preserve-search-language-preference
Open

feat: preserve user's language preference in search page#1775
akshat1074 wants to merge 3 commits intohyperdxio:mainfrom
akshat1074:feat/preserve-search-language-preference

Conversation

@akshat1074
Copy link

@akshat1074 akshat1074 commented Feb 22, 2026

Fixes #1666
Problem
Users' search language preference (SQL vs Lucene) was not being preserved across page refreshes. The default was hardcoded to 'lucene' in multiple places, so switching to SQL would reset back to Lucene on every page reload.
Root Cause
The whereLanguage field was hardcoded to 'lucene' as the default in setSearchedConfig and useForm, with no mechanism to remember the user's preference.
Changes Made

  1. onLanguageChange — When the user toggles the language, their preference is now saved to localStorage immediately:
    tslocalStorage.setItem('hdx-search-language-preference', lang);
  2. useForm initial values — Added localStorage as a fallback when the URL has no language param (e.g. first visit or fresh load):
    tswhereLanguage: searchedConfig.whereLanguage ??
    (localStorage.getItem('hdx-search-language-preference') as 'sql' | 'lucene') ??
    'lucene',
  3. New search default — Same localStorage fallback applied when initializing a new search config.
    Behavior

Toggle language → saved to localStorage instantly
Hit Run → URL updates with correct language
Refresh page → localStorage fallback restores preference
Saved searches → still respect their own stored language preference

Screen.Recording.2026-02-22.175844.mp4

@changeset-bot
Copy link

changeset-bot bot commented Feb 22, 2026

⚠️ No Changeset found

Latest commit: 35ead19

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

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link

vercel bot commented Feb 22, 2026

@akshat1074 is attempting to deploy a commit to the HyperDX Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 22, 2026

PR Review: feat: preserve user's language preference in search page

Summary: Saves/restores language preference (sql/lucene) to localStorage. The previous setSearchedConfig issue has been fixed.


  • ⚠️ localStorage.getItem(...) as 'sql' | 'lucene' is not real validation → A tampered/corrupt value (e.g. 'xss') passes right through. Use a validation check: const lang = localStorage.getItem(...); return (lang === 'sql' || lang === 'lucene') ? lang : null

  • ⚠️ No error handling around localStorage callsgetItem/setItem can throw (storage blocked by policy, quota exceeded). Wrap in try-catch to avoid breaking the component.

  • ⚠️ Omitting whereLanguage from reset() (line ~944) → When searchedConfig changes (URL nav), whereLanguage reverts to defaultValues from mount time, ignoring any whereLanguage embedded in the URL. If a shared/bookmarked URL includes whereLanguage, it will be ignored after the first reset cycle.

  • 🔧 Trailing blank lines left in onLanguageChange → Minor noise; clean up.

@vercel
Copy link

vercel bot commented Feb 23, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
hyperdx-v2-oss-app Ready Ready Preview, Comment Feb 23, 2026 11:12am

Request Review

@elizabetdev
Copy link
Contributor

@akshat1074, thanks for creating this PR. I noticed that when we navigate to another page and then return to the search page, the selected language preference is lost.

Here’s a recording for reference:

Google.Chrome.mp4

I have a PR that creates a new component to handle the SQL/Lucene search input. And I'm adding the user language preference there: #1726.

@akshat1074
Copy link
Author

@elizabetdev – Thanks to you! My approach was so naive compared to yours. Yours was so professional, and I’ve learned so much . Would love to connect and continue learning.

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.

Allow preserving user's language preference in search page WHERE input

2 participants