Skip to content

Commit

Permalink
Ensure immutability in useNoRecursiveRenders
Browse files Browse the repository at this point in the history
  • Loading branch information
gziolo committed Mar 8, 2021

Unverified

This user has not yet uploaded their public signing key.
1 parent f449b10 commit 70069e1
Showing 1 changed file with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -25,14 +25,14 @@ const RenderedRefsContext = createContext( {} );
* @return {Object} The list of rendered blocks grouped by block name.
*/
function addToBlockType( renderedBlocks, blockName, uniqueId ) {
const result = { ...renderedBlocks };
if ( result[ blockName ] ) {
result[ blockName ].add( uniqueId );
} else {
const value = new Set();
value.add( uniqueId );
result[ blockName ] = value;
}
const result = {
...renderedBlocks,
[ blockName ]: renderedBlocks[ blockName ]
? new Set( renderedBlocks[ blockName ] )
: new Set(),
};
result[ blockName ].add( uniqueId );

return result;
}

@@ -52,8 +52,8 @@ function addToBlockType( renderedBlocks, blockName, uniqueId ) {
export default function useNoRecursiveRenders( uniqueId ) {
const previouslyRenderedBlocks = useContext( RenderedRefsContext );
const { name: blockName } = useBlockEditContext();
const hasAlreadyRendered = previouslyRenderedBlocks[ blockName ]?.has(
uniqueId
const hasAlreadyRendered = Boolean(
previouslyRenderedBlocks[ blockName ]?.has( uniqueId )
);
const newRenderedBlocks = useMemo(
() => addToBlockType( previouslyRenderedBlocks, blockName, uniqueId ),

0 comments on commit 70069e1

Please sign in to comment.