-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Block editor: move layout styles to document head (instead of rendering inline) #32083
Conversation
@@ -64,6 +77,8 @@ function Root( { className, children } ) { | |||
} | |||
) } | |||
> | |||
{ element && | |||
createPortal( <BlockHeadSlot />, element.ownerDocument.head ) } |
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.
Ideally it would be good if the portal can be created by the component adding the styles, but there's currently no good way to access the block ref (and the owner document). A future refactor should enable that.
Size Change: +57 B (0%) Total Size: 1.07 MB
ℹ️ View Unchanged
|
Is it possible to avoid the slots here? Can't we just use |
We should also do the same for other hooks that add styles like that. I'm thinking about duotone and elements. |
Yes, we should do the same. There's no way to avoid the slot for now I think, because the Block filter doesn't have access to the owner document. |
What about the frontend? Do we have the same inline style tags there? should we try to move them as well? |
Oh, yes. I didn't think about that :) |
Also wonder who the lazy loading of styles currently work? Can we use similar techniques (in the frontend) cc @aristath |
6a09a19
to
10c98d2
Compare
@youknowriad So this is related to something I'm wondering about. There's a few options where to put the style elements, but for layout style, it seems better to load them in the head because you wouldn't wan't any structural shifts after the content has rendered on the page. Lazy loading the styles seems completely out of the question? |
e1fc1e5
to
9a417f5
Compare
Lazy loading styles works on the frontend because everything goes through |
9a417f5
to
13d81d9
Compare
Getting an error with the CPT "lock all" template, which happens when the content is replaced in the store though
|
Error should be resolved now. Would be good to get this into the release for the template editor. |
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.
Changes look good and this works as expected for me.
I see that we have a few different places in which we output <style>
tags within the body that we could look into consolidating for clarity in a follow-up.
075e5f9
to
d738caa
Compare
d738caa
to
855a9ce
Compare
lib/block-supports/layout.php
Outdated
add_action( | ||
'wp_head', | ||
function () use ( $style ) { | ||
echo '<style>' . $style . '</style>'; | ||
} | ||
); |
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 do believe using wp_head
here will only work for block based themes.
On classic themes the content isn't parsed after wp_head
is already runned so this will never get printed. Basically the same reason global styles are loaded in the footer when loading core assets individually. See https://core.trac.wordpress.org/changeset/51309
2a39dc3
to
5b55a9d
Compare
@ajlende Removed the |
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.
👍 Working for me now
Personally, I don't fell confident adding this to 5.8 that late. What do you think about leaving this for a potential 5.8.x and have a couple plugin releases with it? |
Sounds good to me. |
@@ -240,13 +242,19 @@ const withDuotoneStyles = createHigherOrderComponent( | |||
|
|||
const className = classnames( props?.className, id ); | |||
|
|||
const element = useContext( Head.context ); |
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.
This breaks the hooks rules (it should be called before the if call above)
@@ -210,12 +212,18 @@ export const withLayoutStyles = createHigherOrderComponent( | |||
`wp-container-${ id }` | |||
); | |||
|
|||
const element = useContext( Head.context ); |
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.
same here
* Fix API docs generation (#33384) * Docs: use markdown headings instead of links for API declarations (#33381) * Docs: Run Prettier after updating API in documentation (#33498) (cherry picked from commit 626f233) * Use tabs instead of spaces in block transform doc example (#33549) (cherry picked from commit 8afca1e) * Fix metabox reordering (#30617). * Block editor: don't render layout and duotone styles in between blocks (#32083) * Widgets: Allow HTML tags in description (#33814) * Widgets: Allow HTML tags in description * Use `dangerouslySetInnerHTML` Avoid `<div />` inside the `<p />` tag * Describe by dangerouslySetInnerHTML is used * Use safeHTML * Update comment * Editor: Set 'hide_empty' for the most used terms query (#33457) Don't include terms that aren't assigned to any posts as "most used" terms. * Update widget editor help links to point to the new support article (#33482) * If select-all fires in .editor-post-title__input, end the process.. (#33621) * Writing flow: select all: remove early return for post title (#33699) * Call onChangeSectionExpanded conditionally (#33618) * FontSizePicker: Use number values when the initial value is a number (#33679) * FontSizePicker: Don't use units if the value is a number * Add unit tests * Disable units when we have number values * Fix justification for button block when selected (#33739) * Remove margin setting, auto right conflict with justify buttons * Per review, add little margin back * Add error boundaries to widget screens (#33771) * Add error boundary to edit widgets screen * Add error boundary to customize widgets * Refactor sidebar controls provider to application level so that its state is not lost when re-initializing * Revert "Refactor sidebar controls provider to application level so that its state is not lost when re-initializing" This reverts commit 7d607ff. * Remove rebootability from customize widgets * Remove debug code * Fix insertion point in Widgets editors (#33802) * Default batch processor: Respect the batch endpoint's maxItems (#34280) This updates the default batch processor to make multiple batch requests if the number of requests to process exceeds the number of requests that the batch endpoint can handle. We determine the number of requests that the batch endpoint can handle by making a preflight OPTIONS request to /batch/v1. By default it is 25 requests. See https://make.wordpress.org/core/2020/11/20/rest-api-batch-framework-in-wordpress-5-6/. * Fix button block focus trap after a URL has been added (#34314) * Rework button block link UI to match RichText format implementation * Refine some more, determine visibility by selection and url state * Add e2e test * Also focus rich text when unlinking using a keyboard shortcut * Text for dropdown fields within legacy widgets in the Customizer is off centered (#34076) * Fix ESLint errors reported * Regenerate autogenerated docs * Update the `INSERTER_SEARCH_SELECTOR` path. This is a partial cherry pick of 2356b2d in order to fix the performance tests. Co-authored-by: André <nosolosw@users.noreply.github.com> Co-authored-by: JuanMa <juanma.garrido@gmail.com> Co-authored-by: Greg Ziółkowski <grzegorz@gziolo.pl> Co-authored-by: Jeff Bowen <jblz@users.noreply.github.com> Co-authored-by: Bruno Ribarić <43731400+ribaricplusplus@users.noreply.github.com> Co-authored-by: Ella van Durpe <4710635+ellatrix@users.noreply.github.com> Co-authored-by: Petter Walbø Johnsgård <petter@dekode.no> Co-authored-by: George Mamadashvili <georgemamadashvili@gmail.com> Co-authored-by: Daniel Richards <daniel.richards@automattic.com> Co-authored-by: Hiroshi Urabe <mail@torounit.com> Co-authored-by: Kai Hao <kevin830726@gmail.com> Co-authored-by: Marcus Kazmierczak <marcus@mkaz.com> Co-authored-by: Robert Anderson <robert@noisysocks.com> Co-authored-by: Anton Vlasenko <43744263+anton-vlasenko@users.noreply.github.com>
Follow-up PR at #38750 |
Description
Fixes #30500.
How has this been tested?
Screenshots
Types of changes
Checklist:
*.native.js
files for terms that need renaming or removal).