Skip to content

Commit

Permalink
formatting tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
nmanu1 committed Feb 15, 2024
1 parent 9952690 commit f77e463
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 36 deletions.
1 change: 0 additions & 1 deletion src/components/Filters/CheckboxOption.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ export function CheckboxOption(props: CheckboxOptionProps): JSX.Element | null {
displayName = props.value,
resultsCount
} = props;

const cssClasses = useComposedCssClasses(builtInCssClasses, props.customCssClasses);
const optionId = useId();
const { selectFilter, filters, applyFilters } = useFiltersContext();
Expand Down
64 changes: 32 additions & 32 deletions src/hooks/useId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import { useLayoutEffect } from "./useLayoutEffect";
let serverHandoffComplete = false;
let id = 0;
function genId(): string {
++id;
return id.toString();
++id;
return id.toString();
}

// Workaround for https://github.com/webpack/webpack/issues/14814
// https://github.com/eps1lon/material-ui/blob/8d5f135b4d7a58253a99ab56dce4ac8de61f5dc1/packages/mui-utils/src/useId.ts#L21
const maybeReactUseId: undefined | (() => string) = (React as any)[
"useId".toString()
"useId".toString()
];

/**
Expand All @@ -29,33 +29,33 @@ const maybeReactUseId: undefined | (() => string) = (React as any)[
*/

export function useId(): string {
if (maybeReactUseId !== undefined) {
return maybeReactUseId();
}

// If this instance isn't part of the initial render, we don't have to do the
// double render/patch-up dance. We can just generate the ID and return it.
const initialId = (serverHandoffComplete ? genId() : '');
const [id, setId] = useState(initialId);

useLayoutEffect(() => {
if (id === '') {
// Patch the ID after render. We do this in `useLayoutEffect` to avoid any
// rendering flicker, though it'll make the first render slower (unlikely
// to matter, but you're welcome to measure your app and let us know if
// it's a problem).
setId(genId());
}
}, [id]);

useEffect(() => {
if (serverHandoffComplete === false) {
// Flag all future uses of `useId` to skip the update dance. This is in
// `useEffect` because it goes after `useLayoutEffect`, ensuring we don't
// accidentally bail out of the patch-up dance prematurely.
serverHandoffComplete = true;
}
}, []);

return id;
if (maybeReactUseId !== undefined) {
return maybeReactUseId();
}

// If this instance isn't part of the initial render, we don't have to do the
// double render/patch-up dance. We can just generate the ID and return it.
const initialId = (serverHandoffComplete ? genId() : '');
const [id, setId] = useState(initialId);

useLayoutEffect(() => {
if (id === '') {
// Patch the ID after render. We do this in `useLayoutEffect` to avoid any
// rendering flicker, though it'll make the first render slower (unlikely
// to matter, but you're welcome to measure your app and let us know if
// it's a problem).
setId(genId());
}
}, [id]);

useEffect(() => {
if (serverHandoffComplete === false) {
// Flag all future uses of `useId` to skip the update dance. This is in
// `useEffect` because it goes after `useLayoutEffect`, ensuring we don't
// accidentally bail out of the patch-up dance prematurely.
serverHandoffComplete = true;
}
}, []);

return id;
}
4 changes: 2 additions & 2 deletions src/hooks/useLayoutEffect.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import useIsomorphicLayoutEffect from 'use-isomorphic-layout-effect';

export const useLayoutEffect = typeof useIsomorphicLayoutEffect === 'function'
? useIsomorphicLayoutEffect
: useIsomorphicLayoutEffect['default'];
? useIsomorphicLayoutEffect
: useIsomorphicLayoutEffect['default'];
2 changes: 1 addition & 1 deletion tests/components/FilterSearch.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { FilterSearch, FilterSearchProps } from '../../src/components/FilterSearch';
import { render, RenderResult, screen } from '@testing-library/react';
import * as searchOperations from '../../src/utils/search-operations';
import userEvent from '@testing-library/user-event';
import * as searchOperations from '../../src/utils/search-operations';
import {
labeledFilterSearchResponse,
unlabeledFilterSearchResponse,
Expand Down
Binary file modified yext-search-ui-react-1.5.0.tgz
Binary file not shown.

0 comments on commit f77e463

Please sign in to comment.