Skip to content

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 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 10 commits into from
Jul 17, 2025
Prev Previous commit
Next Next commit
refactor: move test harness functions back to old spots
  • Loading branch information
Parkreiner committed Jul 15, 2025
commit 9ca576b3beb3457992d5d502443fb6dfb45ee4d3
50 changes: 25 additions & 25 deletions site/src/hooks/debounce.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ afterAll(() => {
jest.clearAllMocks();
});

function renderDebouncedValue<T>(value: T, time: number) {
return renderHook(
({ value, time }: { value: T; time: number }) => {
return useDebouncedValue(value, time);
},
{
initialProps: { value, time },
},
);
}

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

function renderDebouncedValue<T>(value: T, time: number) {
Copy link
Member Author

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

return renderHook(
({ value, time }: { value: T; time: number }) => {
return useDebouncedValue(value, time);
},
{
initialProps: { value, time },
},
);
}

it("Should throw for non-nonnegative integer timeouts", () => {
const invalidInputs: readonly number[] = [
Number.NaN,
Expand Down Expand Up @@ -97,21 +97,21 @@ describe(`${useDebouncedValue.name}`, () => {
});
});

function renderDebouncedFunction<Args extends unknown[]>(
callbackArg: (...args: Args) => void | Promise<void>,
time: number,
) {
return renderHook(
({ callback, time }: { callback: typeof callbackArg; time: number }) => {
return useDebouncedFunction<Args>(callback, time);
},
{
initialProps: { callback: callbackArg, time },
},
);
}

describe(`${useDebouncedFunction.name}`, () => {
function renderDebouncedFunction<Args extends unknown[]>(
callbackArg: (...args: Args) => void | Promise<void>,
time: number,
) {
return renderHook(
({ callback, time }: { callback: typeof callbackArg; time: number }) => {
return useDebouncedFunction<Args>(callback, time);
},
{
initialProps: { callback: callbackArg, time },
},
);
}

describe("input validation", () => {
it("Should throw for non-nonnegative integer timeouts", () => {
const invalidInputs: readonly number[] = [
Expand Down
Loading