Skip to content

fix: remove redundant root wrapper div from self-named widget fragments - #804

Open
davidnuescheler wants to merge 1 commit into
mainfrom
fix/widget-nested-root-div
Open

davidnuescheler wants to merge 1 commit into
mainfrom
fix/widget-nested-root-div

Conversation

@davidnuescheler

Copy link
Copy Markdown
Contributor

Problem

Several widget fragments wrap their content in a <div> using the same class name as the widget's own folder (e.g. <div class="article-center"> inside widgets/article-center/article-center.html). blocks/widget/widget.js's decorate() already stamps that same class (cssPrefix) onto the outer .widget block element before/around injecting the fragment's HTML — so these widgets end up with two nested elements sharing one class name.

This is exactly what caused the recipe-center regression (cde6217, fixed separately): any CSS keyed to that shared class (grid-template-areas, negative margins, > child selectors, etc.) matches both the outer wrapper and the inner fragment root, and can silently break layout — see the recipe-center incident where the outer element became a grid container whose only real content was an unlabeled, auto-placed inner div, collapsing the whole widget to a sliver at desktop widths.

This PR applies the same fix pattern to the other widgets with the identical structural issue: article-center, press-center, search-results, and sales-plp.

Changes

  • Removes the redundant root <div class="{widget-name}"> wrapper from each fragment's HTML, so the fragment's real content becomes the direct children of the outer .widget block (matching the pattern already used correctly by product-list, compare-products, support-search, etc., which use a distinct root class like product-list-widget).
  • Removes the dead <script type="module" src="..."> tags in article-center.html, press-center.html, and search-results.html — scripts inserted via innerHTML never execute in the browser, so these were inert markup left over from copy-paste; the module is already loaded via widget.js's dynamic import().
  • sales-plp.html had no <script> tag, only the wrapper div.

None of these four widgets currently key layout CSS off their own top-level class the way recipe-center did, so this isn't a visible bug fix today — it's removing the same latent structural landmine before a future CSS change (grid, negative margins, child selectors) trips over it again.

Verification

Checked each widget's JS for anything that depended on the removed wrapper or script tag — all of them resolve their root via document.querySelector('.{name}') or receive the widget element directly as a function argument, both of which work correctly (and more correctly) once there's only one matching element. Verified live locally: /articles now renders with exactly one .article-center element (full width, all real children present) instead of a nested pair.

🤖 Generated with Claude Code

…ments

article-center, press-center, search-results, and sales-plp fragments
wrapped their content in a <div> using the same class as the widget
folder (e.g. <div class="article-center">). blocks/widget/widget.js
already stamps that same class onto the outer .widget block element,
so these widgets ended up with two nested elements sharing one class
name. Any CSS keyed to that class (grid-template-areas, negative
margins, > child selectors, etc.) would apply to both elements and
break layout, exactly like the recipe-center regression.

Also drops the dead <script type="module"> tags in the article-center,
press-center, and search-results fragments — scripts inserted via
innerHTML never execute, so these were inert markup; the module is
already loaded by widget.js's dynamic import.

Mirrors the fix already applied to widgets/recipe-center/recipe-center.html.
@aem-code-sync

aem-code-sync Bot commented Aug 12, 2026

Copy link
Copy Markdown

Hello, I'm the AEM Code Sync Bot and I will run some actions to deploy your branch and validate page speed.
In case there are problems, just click a checkbox below to rerun the respective action.

  • Re-run all PSI checks
  • Re-run failed PSI checks
  • Re-sync branch
Commits

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.

1 participant