Skip to content

Enhanced block registration to handle instantiation failures - #3003

Open
girishpanchal30 wants to merge 2 commits into
developmentfrom
bugfix/2969
Open

Enhanced block registration to handle instantiation failures#3003
girishpanchal30 wants to merge 2 commits into
developmentfrom
bugfix/2969

Conversation

@girishpanchal30

@girishpanchal30 girishpanchal30 commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

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

  • Included E2E or unit tests for the changes in this PR.
  • Visual elements are not affected by independent changes.
  • It is at least compatible with the minimum WordPress version.
  • It loads additional script in frontend only if it is required.
  • Does not impact the Core Web Vitals.
  • In case of deprecation, old blocks are safely migrated.
  • It is usable in Widgets and FSE.
  • Copy/Paste is working if the attributes are modified.
  • PR is following the best practices

@pirate-bot

Copy link
Copy Markdown
Contributor

Bundle Size Diff

Package Old Size New Size Diff
Animations 178.33 KB 178.33 KB 0 B (0.00%)
Blocks 1.65 MB 1.65 MB 0 B (0.00%)
CSS 7.83 KB 7.83 KB 0 B (0.00%)
Dashboard 172.49 KB 172.49 KB 0 B (0.00%)
Onboarding 68.14 KB 68.14 KB 0 B (0.00%)
Export Import 4.73 KB 4.73 KB 0 B (0.00%)
Pro 439.82 KB 439.82 KB 0 B (0.00%)

@pirate-bot

pirate-bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Plugin build for c4ceb55 is ready 🛎️!

@girishpanchal30 girishpanchal30 linked an issue Aug 27, 2026 that may be closed by this pull request
@pirate-bot

pirate-bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

E2E Tests

Playwright Test Status: See serial and parallel matrix jobs

Performance Results serverResponse: {"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}

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 );

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dynamic block registration fatals when Posts Grid renderer class is unavailable AMP initialization crashes when Lottie_Block is unavailable

4 participants