Opened 13 months ago
Last modified 8 days ago
#63693 new defect (bug)
wp_should_load_block_assets_on_demand doing it wrong too early
| Reported by: | kkmuffme | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Script Loader | Version: | |
| Severity: | normal | Keywords: | |
| Cc: | Focuses: |
Description
wp_should_load_block_assets_on_demand() calls wp_is_rest_endpoint() which generally only works after parse_request hook (since that's where the constant gets defined) https://github.com/WordPress/wordpress-develop/blob/trunk/src/wp-includes/script-loader.php#L2644 since it will always return false before that hook.
The same thing also for wp_should_load_separate_core_block_assets() https://github.com/WordPress/wordpress-develop/blob/trunk/src/wp-includes/script-loader.php#L2609
However it's often called way too early, e.g. on "init" hook, e.g. in WooCommerce https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/src/Blocks/BlockTypesController.php#L632 and https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/src/Blocks/BlockTypesController.php#L633
Or in WP core itself, e.g. when calling wp_register_style( on "init", it will subsequently call wp_default_styles() and then the load block assets on demand function.
The same also in WP core register_block_type_from_metadata(, essentially all the stuff on init in "blocks" wp-includes, e.g. register_block_core_archives() on init
Or for example even in the file that's declaring those: https://github.com/WordPress/wordpress-develop/blob/trunk/src/wp-includes/script-loader.php#L1798
I guess that all those "init" registered block things should be moved to run later on "parse_request" (or "wp") hook? Or alternatively, remove the "wp_is_rest_endpoint()" check since at the point in time it's called on "init", it's not ready yet and always returns false.
Possibly add a "doing_it_wrong" in wp_is_serving_rest_request for ! did_action( 'parse_request' )
Change History (2)
#2
@
6 months ago
Since 6.9.1 this now also happens for things that are not running on the wp_default_styles hook, e.g. register_block_core_video() from wp-includes/blocks/video.php
Should block registration/asset registration be moved later, e.g. on parse_request or wp, so that the rest context is actually known?
Yes
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Should block registration/asset registration be moved later, e.g. on parse_request or wp, so that the rest context is actually known?
Or instead, should the wp_is_rest_endpoint() check be adjusted/removed in these functions, since it can’t return meaningful results that early anyway? https://EchoedStories.my.id
https://TangledWords.my.id
https://InfiniteInk.my.id
https://TheCuratedCraze.my.id
https://MindsetMeadow.my.id
https://TheDriftedSoul.my.id
https://WhisperingTide.my.id
https://DailyWanderings.my.id
https://FreeformJournal.my.id
https://TheChatterSource.my.id
https://TheWhimsicalBreeze.my.id
https://BrighterBeats.my.id
https://TheHeartScroll.my.id
https://TheWanderSphere.my.id
https://DeepDiveDaily.my.id
https://UnfoldedVisions.my.id
https://CollectiveTrails.my.id
https://DreamJournaler.my.id
https://RisingReflections.my.id
https://StoryNest.my.id
https://OpenTerrain.my.id
https://ThoughtRipples.my.id
https://GlimpseAndGo.my.id
https://WonderWoven.my.id
https://TheCuriousWhirl.my.id
https://InspiredLoom.my.id
https://StoryStreamline.my.id
https://TheVividVerse.my.id
https://LivelyReflections.my.id
https://TheVibeRoom.my.id
https://SeekersMurmur.my.id
https://TheVerveVault.my.id
https://InsightEnclave.my.id
https://PulseJournal.my.id
https://UrbanThoughts.my.id
https://TheEvolvingVoice.my.id
https://BloomingPulse.my.id
https://StoryBreeze.my.id
https://WiseWaves.my.id
https://VibrantChronicles.my.id
https://InfiniteMingle.my.id
https://ThinkInTransit.my.id
https://EchoJournal.my.id
https://WanderInk.my.id
https://TheCuratedStream.my.id
https://MindfulMurmurs.my.id
https://TheDriftingVoice.my.id
https://StoryFountain.my.id
https://WhimsicalRoots.my.id
https://EverydayEcho.my.id
https://FreshFables.my.id
https://BoldMosaic.my.id
https://ThoughtVista.my.id
https://TrailOfInk.my.id
https://TheInspiredDrift.my.id
https://roamandreflect.my.id