Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Refactor usage of __unstableGetClientIdsTree #3104

Merged
merged 9 commits into from
Mar 22, 2024

Conversation

mxkae
Copy link
Contributor

@mxkae mxkae commented Mar 11, 2024

fixes #2798

Copy link

github-actions bot commented Mar 11, 2024

🤖 Pull request artifacts

file commit
pr3104-stackable-3104-merge.zip a33dcab

github-actions bot added a commit that referenced this pull request Mar 11, 2024
Comment on lines 15 to 29
const [ blockCount, setBlockCount ] = useState( null )

// Subscribe to all editor changes, so we can listen in to block structure changes.
subscribe( () => {
const count = select( 'core/block-editor' ).getGlobalBlockCount()
if ( count !== blockCount ) {
setBlockCount( count )
}
} )

useEffect( () => {
if ( blockCount ) {
dispatch( 'stackable/block-editor' ).updateClientTree()
}
}, [ blockCount ] )
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we see if using getClientIdsWithDescendants will help with this?

Suggested change
const [ blockCount, setBlockCount ] = useState( null )
// Subscribe to all editor changes, so we can listen in to block structure changes.
subscribe( () => {
const count = select( 'core/block-editor' ).getGlobalBlockCount()
if ( count !== blockCount ) {
setBlockCount( count )
}
} )
useEffect( () => {
if ( blockCount ) {
dispatch( 'stackable/block-editor' ).updateClientTree()
}
}, [ blockCount ] )
const allClientIds = useSelect( select => {
return select( 'core/block-editor' ).getClientIdsWithDescendants()
} )
useEffect( () => {
console.log('did update' )
dispatch( 'stackable/block-editor' ).updateClientTree()
}, [ allClientIds ] )

github-actions bot added a commit that referenced this pull request Mar 13, 2024
github-actions bot added a commit that referenced this pull request Mar 19, 2024
…-tapiamkr:gambitph/Stackable into fix/2798-refactor-__unstableGetClientIdsTree
github-actions bot added a commit that referenced this pull request Mar 20, 2024
github-actions bot added a commit that referenced this pull request Mar 20, 2024
github-actions bot added a commit that referenced this pull request Mar 20, 2024
github-actions bot added a commit that referenced this pull request Mar 20, 2024
Copy link
Contributor

@bfintal bfintal left a comment

Choose a reason for hiding this comment

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

Now we have 2 stores for this purpose:

  1. src/hooks/use-block-context.js
  2. src/plugins/get-client-id-tree/store.js

I believe both of these are used solely for updating block context, so we should be able to combine these into just one.

github-actions bot added a commit that referenced this pull request Mar 20, 2024
@andeng1106
Copy link

andeng1106 commented Mar 22, 2024

@bfintal bfintal merged commit 578afb0 into develop Mar 22, 2024
1 of 6 checks passed
@bfintal bfintal deleted the fix/2798-refactor-__unstableGetClientIdsTree branch March 22, 2024 12:44
@bfintal bfintal restored the fix/2798-refactor-__unstableGetClientIdsTree branch March 22, 2024 16:42
bfintal added a commit that referenced this pull request Mar 22, 2024
bfintal added a commit that referenced this pull request Mar 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor usage of __unstableGetClientIdsTree before WordPress 6.4
3 participants