Skip to content

Commit

Permalink
Disable ED rule and add context as to why it’s ommitted
Browse files Browse the repository at this point in the history
  • Loading branch information
getdave authored and Alex Lende committed Mar 3, 2023
1 parent d71a839 commit 1f01231
Showing 1 changed file with 46 additions and 33 deletions.
79 changes: 46 additions & 33 deletions packages/block-library/src/navigation/edit/unsaved-inner-blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,40 +120,53 @@ export default function UnsavedInnerBlocks( {
const { hasResolvedNavigationMenus } = useNavigationMenu();

// Automatically save the uncontrolled blocks.
useEffect( () => {
// The block will be disabled when used in a BlockPreview.
// In this case avoid automatic creation of a wp_navigation post.
// Otherwise the user will be spammed with lots of menus!
//
// Also ensure other navigation menus have loaded so an
// accurate name can be created.
//
// Don't try saving when another save is already
// in progress.
//
// And finally only create the menu when the block is selected,
// which is an indication they want to start editing.
if (
isDisabled ||
isSaving ||
! hasResolvedDraftNavigationMenus ||
! hasResolvedNavigationMenus ||
! hasSelection ||
! innerBlocksAreDirty
) {
return;
}
useEffect(
() => {
// The block will be disabled when used in a BlockPreview.
// In this case avoid automatic creation of a wp_navigation post.
// Otherwise the user will be spammed with lots of menus!
//
// Also ensure other navigation menus have loaded so an
// accurate name can be created.
//
// Don't try saving when another save is already
// in progress.
//
// And finally only create the menu when the block is selected,
// which is an indication they want to start editing.
if (
isDisabled ||
isSaving ||
! hasResolvedDraftNavigationMenus ||
! hasResolvedNavigationMenus ||
! hasSelection ||
! innerBlocksAreDirty
) {
return;
}

createNavigationMenu( null, blocks );
}, [
createNavigationMenu,
isDisabled,
isSaving,
hasResolvedDraftNavigationMenus,
hasResolvedNavigationMenus,
innerBlocksAreDirty,
hasSelection,
] );
createNavigationMenu( null, blocks );
},
/* The dependency "blocks" is intentionally omitted here.
* This is because making blocks a dependency would cause
* createNavigationMenu to run on every block change whereas
* we only want it to run when the blocks are first detected
* as dirty.
* A better solution might be to add a hard saving lock using
* a ref to avoid having to disbale theses eslint rules.
*/
/* eslint-disable react-hooks/exhaustive-deps */
[
createNavigationMenu,
isDisabled,
isSaving,
hasResolvedDraftNavigationMenus,
hasResolvedNavigationMenus,
innerBlocksAreDirty,
hasSelection,
]
/* eslint-enable react-hooks/exhaustive-deps */
);

const Wrapper = isSaving ? Disabled : 'div';

Expand Down

0 comments on commit 1f01231

Please sign in to comment.