-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
ref(seer): Persist Seer Explorer input draft per run #115919
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+222
−19
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e7774cd
feat(seer): Persist Seer Explorer input draft per run
aliu39 846fce7
test(seer): Cover input draft persistence in explorer drawer
aliu39 d3da33c
tweak test
aliu39 6b96351
feat(seer): Skip draft persistence when runId is null
aliu39 158e036
refactor to global util
aliu39 79167e6
support null in original
aliu39 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import {useCallback, useEffect, useRef, useState} from 'react'; | ||
|
|
||
| import {sessionStorageWrapper} from 'sentry/utils/sessionStorage'; | ||
| import {readStorageValue, writeStorageValue} from 'sentry/utils/useSessionStorage'; | ||
|
|
||
| function readValue<T>(key: string | null, initialValue: T): T { | ||
| if (key === null) { | ||
| return initialValue; | ||
| } | ||
| return readStorageValue(key, initialValue); | ||
| } | ||
|
|
||
| function writeValue(key: string | null, value: unknown): void { | ||
| if (key === null) { | ||
| return; | ||
| } | ||
| writeStorageValue(key, value); | ||
| } | ||
|
|
||
| /** | ||
| * Persists a value to sessionStorage under `key`. Unlike `useSessionStorage`, writes are deferred — | ||
| * storage is only updated on: | ||
| * - key change (flush old key, load new key) | ||
| * - unmount (flush current key) | ||
| * - explicit `reset()` (drop the persisted value and reset state to initialValue) | ||
| * | ||
| * When `key` is null the storage persistence is disabled - the value lives in React state only. | ||
| */ | ||
| export function useDeferredSessionStorage<T>(key: string | null, initialValue: T) { | ||
| const [value, setValue] = useState(() => readValue(key, initialValue)); | ||
|
|
||
| const keyRef = useRef(key); | ||
| const valueRef = useRef(value); | ||
| valueRef.current = value; | ||
|
|
||
| // Flush to storage and update value on key change | ||
| useEffect(() => { | ||
| if (keyRef.current !== key) { | ||
| writeValue(keyRef.current, valueRef.current); | ||
| setValue(readValue(key, initialValue)); | ||
| keyRef.current = key; | ||
| } | ||
| }, [key, initialValue]); | ||
|
|
||
| // Flush to storage on unmount | ||
| useEffect(() => { | ||
| return () => { | ||
| writeValue(keyRef.current, valueRef.current); | ||
| }; | ||
| }, []); | ||
|
|
||
| const reset = useCallback(() => { | ||
| if (keyRef.current !== null) { | ||
| sessionStorageWrapper.removeItem(keyRef.current); | ||
| } | ||
| setValue(initialValue); | ||
| }, [initialValue]); | ||
|
|
||
| return {value, setValue, reset}; | ||
| } | ||
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unmount cleanup re-writes value after explicit reset
Low Severity
The unmount cleanup effect unconditionally writes
valueRef.currentto storage, which re-creates a storage entry thatreset()explicitly removed viasessionStorageWrapper.removeItem. AfterhandleSendcallsclearInput()(i.e.,reset()), closing the drawer triggers the unmount cleanup and writes theinitialValueback under the same key, creating a zombie entry in sessionStorage. The test for "clears the persisted draft when a message is sent" only passes because it asserts before unmount occurs.Additional Locations (1)
static/app/utils/useDeferredSessionStorage.tsx#L51-L57Reviewed by Cursor Bugbot for commit 158e036. Configure here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wont affect functionality, just an extra storage write on this edge case