Enhanced block registration to handle instantiation failures - #3003
Enhanced block registration to handle instantiation failures#3003girishpanchal30 wants to merge 2 commits into
Conversation
Bundle Size Diff
|
|
Plugin build for c4ceb55 is ready 🛎️!
|
E2E TestsPlaywright Test Status: See serial and parallel matrix jobs Performance ResultsserverResponse: {"q25":514.15,"q50":546.57,"q75":551.98,"cnt":10}, firstPaint: {"q25":1734.36,"q50":1874.04,"q75":2077.56,"cnt":10}, domContentLoaded: {"q25":4396.68,"q50":4458.35,"q75":4497.49,"cnt":10}, loaded: {"q25":4400.05,"q50":4461.76,"q75":4501.17,"cnt":10}, firstContentfulPaint: {"q25":3298.11,"q50":3366.6,"q75":3382.02,"cnt":10}, firstBlock: {"q25":19886.67,"q50":19983.48,"q75":20035.13,"cnt":10}, type: {"q25":31.94,"q50":35.51,"q75":39.79,"cnt":10}, typeWithoutInspector: {"q25":29.89,"q50":33.43,"q75":43.07,"cnt":10}, typeWithTopToolbar: {"q25":40.55,"q50":43.65,"q75":46.63,"cnt":10}, typeContainer: {"q25":17.61,"q50":19.47,"q75":20.13,"cnt":10}, focus: {"q25":161.36,"q50":162.77,"q75":167.11,"cnt":10}, inserterOpen: {"q25":50.38,"q50":54.46,"q75":60.22,"cnt":10}, inserterSearch: {"q25":33.45,"q50":34.55,"q75":36.77,"cnt":10}, inserterHover: {"q25":5.58,"q50":6.19,"q75":7.02,"cnt":20}, loadPatterns: {"q25":2226.6,"q50":2255.73,"q75":2304.38,"cnt":10}, listViewOpen: {"q25":286.65,"q50":295.34,"q75":308.96,"cnt":10} |
There was a problem hiding this comment.
Pull request overview
Improves dynamic and AMP block registration resilience when renderer classes cannot be instantiated.
Changes:
- Adds guarded renderer instantiation with failure logging.
- Falls back to metadata-only block registration.
- Adds failure-path tests and updates PHPStan baseline.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
inc/class-registration.php |
Safely instantiates dynamic and AMP renderers. |
tests/test-registration.php |
Adds renderer failure tests. |
phpstan-baseline.neon |
Removes obsolete suppression. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
|
||
| foreach ( $classnames as $classname ) { | ||
| $classname = new $classname(); | ||
| $instance = self::instantiate_safely( $classname ); |
There was a problem hiding this comment.
The current class instantiation check is correct for both dynamic block and AMP block classes. In the test case, I have verified that the new method correctly checks whether the class exists before creating its instance.
There is no need to add an extra test case for the AMP block that injects Lottie_Block through a filter, as I have already verified that the instantiate_safely() method initializes the class instance with the proper guard in the existing test case. The same logic applies to the AMP path, so the current test coverage is sufficient.
Closes #2969, #2955
Summary
Ensure that the dynamic block class is correctly initialized, if the class is not initialized, then log the error and skip the block registration.
Checklist before the final review