-
Notifications
You must be signed in to change notification settings - Fork 894
feat: make workspace search bar remember text #9759
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
Merged
Changes from 13 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
2f92f86
minor: Add useEffectEvent polyfill
Parkreiner e2d3a67
chore: update filter to have better callback support
Parkreiner eeb3083
docs: Clean up comments
Parkreiner 553ce89
fix: add localStorage to useWorkspacesFilter
Parkreiner b06d772
refactor: Centralize stable useSearchParams
Parkreiner df1f8df
refactor: clean up filter to be fully pure on mount
Parkreiner 29656c1
chore: add tests for useEffectEvent
Parkreiner 54a5940
wip: commit progress for searchbar fix
Parkreiner ae5b359
chore: clean up WorkspacesPage
Parkreiner 7dd1b4f
fix: add logic for syncing queries with search params
Parkreiner ab9de0c
chore: Rename initialValue to fallbackFilter
Parkreiner 391648a
chore: Remove todo comment
Parkreiner 7e15671
Merge branch 'main' into workspace-searchbar-storage
Parkreiner 60e9b10
Merge branch 'main' into workspace-searchbar-storage
Parkreiner dfad46f
refactor: update code to use useEffectEvent
Parkreiner dcd8691
docs: clean up comments for clarity
Parkreiner 3a7efd5
fix: update url check to use regex
Parkreiner 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
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,48 @@ | ||
import { renderHook } from "@testing-library/react"; | ||
import { useEffectEvent } from "./hookPolyfills"; | ||
|
||
function renderEffectEvent<TArgs extends unknown[], TReturn = unknown>( | ||
callbackArg: (...args: TArgs) => TReturn, | ||
) { | ||
return renderHook( | ||
({ callback }: { callback: typeof callbackArg }) => { | ||
return useEffectEvent(callback); | ||
}, | ||
{ | ||
initialProps: { callback: callbackArg }, | ||
}, | ||
); | ||
} | ||
|
||
describe(`${useEffectEvent.name}`, () => { | ||
it("Should maintain a stable reference across all renders", () => { | ||
const callback = jest.fn(); | ||
const { result, rerender } = renderEffectEvent(callback); | ||
|
||
const firstResult = result.current; | ||
for (let i = 0; i < 5; i++) { | ||
rerender({ callback }); | ||
} | ||
|
||
expect(result.current).toBe(firstResult); | ||
expect.hasAssertions(); | ||
}); | ||
|
||
it("Should always call the most recent callback passed in", () => { | ||
let value: "A" | "B" | "C" = "A"; | ||
const flipToB = () => { | ||
value = "B"; | ||
}; | ||
|
||
const flipToC = () => { | ||
value = "C"; | ||
}; | ||
|
||
const { result, rerender } = renderEffectEvent(flipToB); | ||
rerender({ callback: flipToC }); | ||
|
||
result.current(); | ||
expect(value).toEqual("C"); | ||
expect.hasAssertions(); | ||
}); | ||
}); |
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,37 @@ | ||
/** | ||
* @file For defining DIY versions of official React hooks that have not been | ||
* released yet. | ||
* | ||
* These hooks should be deleted as soon as the official versions are available. | ||
* They do not have the same ESLinter exceptions baked in that the official | ||
* hooks do, especially for dependency arrays. | ||
*/ | ||
import { useCallback, useEffect, useRef } from "react"; | ||
|
||
/** | ||
* A DIY version of useEffectEvent. | ||
* | ||
* Works like useCallback, except that it doesn't take a dependency array, and | ||
* always returns out a stable function on every single render. The returned-out | ||
* function is always able to "see" the most up-to-date version of the callback | ||
* passed in. | ||
* | ||
* Should only be used as a last resort when useCallback does not work, but you | ||
* still need to avoid dependency array violations. (e.g., You need an on-mount | ||
* effect, but an external library doesn't give their functions stable | ||
* references, so useEffect/useMemo/useCallback run too often). | ||
* | ||
* @see {@link https://react.dev/reference/react/experimental_useEffectEvent} | ||
*/ | ||
export function useEffectEvent<TArgs extends unknown[], TReturn = unknown>( | ||
callback: (...args: TArgs) => TReturn, | ||
) { | ||
const callbackRef = useRef(callback); | ||
useEffect(() => { | ||
callbackRef.current = callback; | ||
}, [callback]); | ||
|
||
return useCallback((...args: TArgs): TReturn => { | ||
return callbackRef.current(...args); | ||
}, []); | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.