-
Notifications
You must be signed in to change notification settings - Fork 4.7k
[Site Editor]: Set html block as freeform fallback block
#48129
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
Merged
ntsekouras
merged 1 commit into
trunk
from
update/freeform-fallback-to-html-block-in-site-editor
Feb 23, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens in the Widget editor and other spinoffs? 😉
This feels hacky and exposes other underlying fragilities:
registerCoreBlocksimplicitly callssetFreeformFallbackBlockNameand then we override that here by callingsetFreeformFallbackBlockNameagain.registerCoreBlocksaccepts an optional argument to override the default selection of block types to register. However, it doesn't take the (IMO necessary) precaution to check thatcore/freeformis actually on the list of registered blocks before setting it as the fallback.registerCoreBlocksalready does some checking (if ( window.wp && window.wp.oldEditor ) {), but it is clearly insufficient.So I would start from that condition:
blocksarrayThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. I didn't think about this check
window.wp?.oldEditortoo much and had the impression that it was not defined in site editor, but what we actually checked was only if it was a WP environment.In general,
registerCoreBlocksprobably does more than it should IMO and we should better handle this separately. At first I thought about adding anoptionobject that thegrouping, default, etc..blocks could be set. The problem is bigger though, as we should not only have guards here about these blocks, but also in other actions likeunregisterBlock, etc.. because we rely in many places about these blocks to be set.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm probably more comfortable at the outset with calling
setFreeformFallbackBlockName. @mcsf if not in a place like this, where would you expect people to call it?it would make me just as happy to remove that entirely from state and instead have this statically set at editor boot.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'm not really liking the tight coupling in
registerCoreBlocks, despite what I said. It's also arguably too big a change for something implicit; that could break stuff in third-party editors, etc.Thinking aloud:
initializeEditorfunction. As was Nik's intuition, this is the most natural place to do this sort of imperative configuration.settings(a two-part pipeline starting in the server as$editor_settingsand ending in the client ininitializeEditor). There's always the possibility of introducing optional settings for this kind of stuff instead. It's more declarative, but I'm also wary of introducing a setting when other APIs already exist (even if they are imperative).registerCoreBlockscame because that function was already making implicit choices (and doing them poorly, since it wasn't properly checking forwindow.tinymce). Well, what if we separate these two problems. That is:registerCoreBlocks. Instead of automatically falling back to other block types, just throw a loggable error ("Cannot set xyz as fallback block type: block type not found.").initializeEditor.Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it all seems fine to me.
settingsseems like the same general idea I had concerning "statically set at editor boot."this is more or less why I'm fine with a raggy solution now, because I doubt it would very much change the existing situation or impede improvements.
if the site editor needs to replace the fallback block then it only needs to ensure that happens before a post is loaded.
getting this into a more declarative spot might take a little more thought, whereas the imperative approach already exists and announces itself basically as the way to do it right now.
hopefully it's clear I have almost no concern about how this change is implemented at this stage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kept only my initial commit and it seems the other screens already did that(1, 2).
Maybe we could fix this as is part of
6.2and handle in a follow up the better handling in registerBlocks? What do you think @mcsf ?