Skip to content

Commit

Permalink
refactor: BlockList uses Hooks (#50293)
Browse files Browse the repository at this point in the history
* refactor: BlockList EmptyList uses Hooks

Adopt modern React paradigms prior to refactoring the components
composition. Completed to more closely mirror other code in the code
base.

* refactor: BlockList uses Hooks

Adopt modern React paradigms prior to refactoring the components
composition. Completed to more closely mirror other code in the code
base.

* refactor: BlockList higher-order components use Hooks

Adopt modern React paradigms prior to refactoring the components
composition. Completed to more closely mirror other code in the code
base.

Additionally, this removes the `withPreferredColorScheme` higher-order
component as it appeared unused.

* fix: BlockList footer interactivity

`VirtualList` expects a React Component (e.g. `SomeComponent`), or a
React element (e.g. `<SomeComponent` />) passed to the
`ListFooterComponent` prop. Passing a function instead resulted in the
block inserter never opening when tapping the block appender button
within the footer; this appeared to be due to excessive re-renders
resetting the `isOpen` state for the inserter.

* fix: Rename Footer addBlockToEndOfPost callback prop

The typo led to an undefined callback function.

* fix: Reinstate missing prop used within store selector

This prop was originally accessed via the `withSelect` higher-order
component. When converting to Hooks, passing this prop was overlooked.

* fix: Scope timer run by `waitForStoreResolvers`

Running all timers could create testing failures in scenarios wheres
where inner blocks were inserted, e.g. Social Icons. It is not known
why, but scoping from "all" to "pending" timers resolved the following
errors, without breaking any existing tests.

Unknown origin:

```
Warning: You seem to have overlapping act() calls, this is not supported. Be sure to await previous act() calls before making a new one.
```

Originating from `waitForStoreResolvers`:

```
Ran 100000 timers, and there are still more! Assuming we've hit an infinite recursion and bailing out...
```

Originating from `packages/block-editor/src/components/block-list/test/index.native.js`:

```
thrown: "Exceeded timeout of 5000 ms for a test.
```

* test: BlockList renders footer appender

* typo: Add code comment

Added to align with sibling tests.

* test: Expand empty BlockList appender tests
  • Loading branch information
dcalhoun committed May 8, 2023
1 parent f4730d7 commit 023631c
Show file tree
Hide file tree
Showing 4 changed files with 279 additions and 309 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,23 @@ import { View } from 'react-native';
* WordPress dependencies
*/
import { useEffect, useCallback } from '@wordpress/element';
import { useSelect } from '@wordpress/data';

/**
* Internal dependencies
*/
import { useBlockListContext } from './block-list-context';
import { store as blockEditorStore } from '../../store';

function BlockListItemCell( { children, clientId, rootClientId, onLayout } ) {
function BlockListItemCell( { children, item: clientId, onLayout } ) {
const { blocksLayouts, updateBlocksLayouts } = useBlockListContext();
const { rootClientId } = useSelect(
( select ) => {
const { getBlockRootClientId } = select( blockEditorStore );
return { rootClientId: getBlockRootClientId( clientId ) };
},
[ clientId ]
);

useEffect( () => {
return () => {
Expand Down
Loading

1 comment on commit 023631c

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 023631c.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4916347031
📝 Reported issues:

Please sign in to comment.