This repository has been archived by the owner on Feb 23, 2024. It is now read-only.
Fix Product Search block in last Gutenberg release #1841
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #1825.
It took me a while to understand what was going on in #1825 and I don't fully understand everything yet. What I found out is that using React hooks inside the render function doesn't play well with Gutenberg and makes it crash.
In fact, we were not directly using React hooks in the render function, but we used
withInstanceId
, which was updated recently to use hooks (see WordPress/gutenberg#19091).In order to fix this, and considering we only need the
instanceId
in the editor, this PR splitsProductSearchBlock
into two components: one for the save function and another one for the editor, as we do for most of the other blocks.Note: if it's difficult to merge this PR into
release/2.5
, e101b0c is a quick work-around that switcheswithInstanceId
from Gutenberg for ourwithComponentId
, which doesn't use hooks internally so it doesn't make the block crash. But that is not a future-proof solution because if we ever changedwithComponentId
to use hooks, the issue would appear again. So at least inmaster
we should merge this PR entirely.How to test the changes in this Pull Request:
master
with Gutenberg disabled create a post or page with a Product Search block.Changelog