Skip to content

Improved component resolution handling - #4592

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

Improved component resolution handling#4592
girishpanchal30 wants to merge 2 commits into
developmentfrom
bugfix/4565

Conversation

@girishpanchal30

Copy link
Copy Markdown
Contributor

Summary

Improves the reliability and safety of component resolution in the header-footer grid system by adding guards to prevent errors when a component cannot be found. It updates several component templates to bail early if the current component is unresolvable and adds comprehensive unit tests to ensure these guards work as intended.

Check before Pull Request is ready:

Closes #4565

@pirate-bot

pirate-bot commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator

Plugin build for 11aeb5c is ready 🛎️!

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds safer HFG component resolution to avoid warnings/notices when the render context is missing/stale, and verifies the behavior via unit tests.

Changes:

  • Add guard logic to Abstract_Builder::get_component() to return null for missing/unknown component IDs.
  • Update component templates to bail out early when current_component() can’t be resolved.
  • Add WP unit tests covering unknown/stale component IDs and template rendering behavior.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/test-neve-hfg-component-guards.php Adds unit tests for component resolution guards and template no-output behavior
header-footer-grid/Core/Builder/Abstract_Builder.php Ensures get_component() returns null for null/unknown IDs
header-footer-grid/functions-template.php Updates current_component() return type doc to include null
header-footer-grid/templates/components/component-nav.php Avoids calling methods on an unresolvable component
header-footer-grid/templates/components/component-logo.php Avoids calling methods on an unresolvable component
header-footer-grid/templates/components/component-footer-sidebar.php Avoids calling methods on an unresolvable component; reuses resolved component
header-footer-grid/templates/component-wrapper.php Avoids calling methods on an unresolvable component; reuses resolved component

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread header-footer-grid/templates/components/component-nav.php Outdated
Comment thread header-footer-grid/functions-template.php Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.

Suppressed comments (2)

header-footer-grid/templates/components/component-nav.php:22

  • This can still emit an Undefined index: device notice when $args is non-empty but does not contain a device key. Use a key-level check (e.g., isset( $args['device'] )) or null coalescing ($args['device'] ?? '') to avoid notices.
$device_class          = isset( $args ) && ! empty( $args ) ? $args['device'] : '';

header-footer-grid/templates/component-wrapper.php:16

  • The same component-resolution guard pattern is duplicated across multiple templates in this PR. Consider centralizing the logic in a small helper (e.g., a function that returns ?Abstract_Component or bails for templates) to reduce repetition and keep future guard behavior consistent.
$_component = current_component();

// Bail when the current component cannot be resolved on the current builder.
if ( ! $_component instanceof Core\Components\Abstract_Component ) {
	return;
}

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.

Customizer selective refresh can fatal when component lookup returns null

4 participants