Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(site): speed up state syncs and validate input for debounce hook logic#18877

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Parkreiner merged 10 commits intomainfrommes/debounce-fix
Jul 17, 2025

Conversation

Parkreiner
Copy link
Member

No issue to link – I'm basically pushing some updates upstream from the version of the hook I copied over for the Registry website.

Changes made

  • Updated debounce functions to have input validation for timeouts
  • UpdateduseDebouncedValue to flush state syncs immediately if timeout value is0
  • Updated tests to reflect changes
  • Cleaned up some comments and parameter names to make things more clear

@ParkreinerParkreiner self-assigned thisJul 15, 2025
value: T,
debounceTimeMs: number,
): T {
export function useDebouncedValue<T>(value: T, debounceTimeoutMs: number): T {
Copy link
MemberAuthor

@ParkreinerParkreinerJul 15, 2025
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Removed the default parameter here because if you, the user of the hook, don't know the type of a value you're trying to debounce, you're probably doing somethingreally wrong

);
}

const timeoutIdRef = useRef<number | undefined>(undefined);
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Updated ref type to match the type used by the browser'ssetTimeout

@@ -12,7 +12,7 @@ afterAll(() => {
});

describe(`${useDebouncedValue.name}`, () => {
function renderDebouncedValue<T = unknown>(value: T, time: number) {
function renderDebouncedValue<T>(value: T, time: number) {
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Default type parameter removed to match new type signature for the main hook

@ParkreinerParkreiner requested a review fromaslilacJuly 15, 2025 14:28
@@ -12,7 +12,7 @@ afterAll(() => {
});

describe(`${useDebouncedValue.name}`, () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
describe(`${useDebouncedValue.name}`,()=>{
describe(useDebouncedValue.name,()=>{

I know you didn't change this line, but just noticed

): UseDebouncedFunctionReturn<Args> {
if (!Number.isInteger(debounceTimeoutMs) || debounceTimeoutMs < 0) {
throw new Error(
`Provided debounce value ${debounceTimeoutMs} must be a non-negative integer`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Provided debounce value -1 must be a non-negative integer

I'm not sure this wording makes much sense. how about something like...

Suggested change
`Provided debouncevalue${debounceTimeoutMs}must bea non-negative integer`,
`Invalidvalue${debounceTimeoutMS} for debounceTimeoutMs. Valuemust begreater than or equal to zero.`,

export function useDebouncedValue<T>(value: T, debounceTimeoutMs: number): T {
if (!Number.isInteger(debounceTimeoutMs) || debounceTimeoutMs < 0) {
throw new Error(
`Provided debounce value ${debounceTimeoutMs} must be a non-negative integer`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Same thing here

@ParkreinerParkreiner changed the titlefix(site): speed up state syncs and add input validation for debounce hook logicfix(site): speed up state syncs and validate input for debounce hook logicJul 17, 2025
@ParkreinerParkreiner merged commitf47efc6 intomainJul 17, 2025
33 checks passed
@ParkreinerParkreiner deleted the mes/debounce-fix branchJuly 17, 2025 22:15
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsJul 17, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@aslilacaslilacaslilac approved these changes

Assignees

@ParkreinerParkreiner

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@Parkreiner@aslilac

[8]ページ先頭

©2009-2025 Movatter.jp