-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
[Site Editor]: Set html
block as freeform fallback block
#48129
[Site Editor]: Set html
block as freeform fallback block
#48129
Conversation
Size Change: -1 B (0%) Total Size: 1.33 MB
ℹ️ View Unchanged
|
Flaky tests detected in fc4654f. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4240969123
|
( { name } ) => name !== 'core/freeform' | ||
); | ||
registerCoreBlocks( coreBlocks ); | ||
dispatch( blocksStore ).setFreeformFallbackBlockName( 'core/html' ); |
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:
registerCoreBlocks
implicitly callssetFreeformFallbackBlockName
and then we override that here by callingsetFreeformFallbackBlockName
again.registerCoreBlocks
accepts 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/freeform
is actually on the list of registered blocks before setting it as the fallback.- This solution, as I mentioned, requires all editors instances to do this kind of failure checking.
- Supposedly,
registerCoreBlocks
already does some checking (if ( window.wp && window.wp.oldEditor ) {
), but it is clearly insufficient.
So I would start from that condition:
- Ensure it's actually testing for the presence of TinyMCE
- Ensure that it doesn't set Freeform as the fallback if it's not included in the
blocks
array - ... and then we'll see what is left to do :)
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.
Makes sense. I didn't think about this check window.wp?.oldEditor
too 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, registerCoreBlocks
probably does more than it should IMO and we should better handle this separately. At first I thought about adding an option
object that the grouping, 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 like unregisterBlock
, 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.
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.
Thinking aloud:
- The closest thing we have to a "standard init interface" is each editor's
initializeEditor
function. As was Nik's intuition, this is the most natural place to do this sort of imperative configuration. - We also have editor
settings
(a two-part pipeline starting in the server as$editor_settings
and 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). - I think my initial reflex to fix this directly in
registerCoreBlocks
came 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:- Don't try to be smart in
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."). - Thus, go back to Nik's original approach and update all of core's non-post editors so that they explicitly set their freeform handler to HTML in
initializeEditor
. - Fix the Classic block so that it checks for the presence of TinyMCE instead of just blindly failing.
- Don't try to be smart in
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. settings
seems like the same general idea I had concerning "statically set at editor boot."
making implicit choices (and doing them poorly,
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.
de6afd1
to
4daf31c
Compare
4daf31c
to
fc4654f
Compare
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.
LGTM!
An additional test scenario that I tried:
Expected:
|
@ntsekouras @mcsf @dmsnell I just realized this PR existed and went to test the following use case: add an empty HTML comment (meaning no content as a child). My expectation was that the comment would be ignored. Instead, it was converted to a block. Steps:
<!--
title: Title for the template or part
area: related-area
-->
Would you think there's a way to follow up this PR and ignore HTML comments with no content? While the issue reported caused a bug, the original intent was that the comments would be ignored, so we can attach metadata to the template via HTML comments, as in #38984 |
@oandregal: yeah, we fixed the worst part, which was the crash, but the rendering of comments is still something to address. Could you turn your comment into an issue and link it to #47212? 🙏 IMO, this part will be the hardest to fix if we want to fix it properly. |
Issue at #48408 |
I just cherry-picked this PR to the wp/6.2 branch to get it included in the next release: abf45f5 |
What?
Resolves: #47212
This PR does two things:
core/html
block as a fallback freeform fallback block in site editor(this is the resolution of the issue)__unstableCanInsertBlockType
forclassic
block and achieves the same behavior by not registering it.Testing Instructions for
html
block fallback<p>Hello World</p>
in a block themehtml
blocks are used for the above.Testing Instructions for
classic
block not available in site editorclassic
block