-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix render loop in
<Modal>
, clean up ref merger code
(cherry picked from commit 893a77a)
- Loading branch information
1 parent
c5f8b61
commit c9223c7
Showing
8 changed files
with
40 additions
and
38 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 |
---|---|---|
@@ -1,30 +1,6 @@ | ||
// Copyright 2019-2020 Signal Messenger, LLC | ||
// Copyright 2019-2021 Signal Messenger, LLC | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
|
||
import { MutableRefObject, Ref } from 'react'; | ||
import { isFunction } from 'lodash'; | ||
import memoizee from 'memoizee'; | ||
|
||
export function cleanId(id: string): string { | ||
return id.replace(/[^\u0020-\u007e\u00a0-\u00ff]/g, '_'); | ||
} | ||
|
||
// Memoizee makes this difficult. | ||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types | ||
export const createRefMerger = () => | ||
memoizee( | ||
<T>(...refs: Array<Ref<T>>) => { | ||
return (t: T) => { | ||
refs.forEach(r => { | ||
if (isFunction(r)) { | ||
r(t); | ||
} else if (r) { | ||
// Using a MutableRefObject as intended | ||
// eslint-disable-next-line no-param-reassign | ||
(r as MutableRefObject<T>).current = t; | ||
} | ||
}); | ||
}; | ||
}, | ||
{ length: false, max: 1 } | ||
); |
This file contains 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 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 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,8 @@ | ||
// Copyright 2021 Signal Messenger, LLC | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
|
||
import { useMemo } from 'react'; | ||
import { createRefMerger } from '../util/refMerger'; | ||
|
||
export const useRefMerger = (): ReturnType<typeof createRefMerger> => | ||
useMemo(createRefMerger, []); |
This file contains 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