fix: remove redundant root wrapper div from self-named widget fragments - #804
Open
davidnuescheler wants to merge 1 commit into
Open
davidnuescheler wants to merge 1 commit into
davidnuescheler wants to merge 1 commit into
Conversation
…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.
|
Hello, I'm the AEM Code Sync Bot and I will run some actions to deploy your branch and validate page speed.
Commits
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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">insidewidgets/article-center/article-center.html).blocks/widget/widget.js'sdecorate()already stamps that same class (cssPrefix) onto the outer.widgetblock 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, andsales-plp.Changes
<div class="{widget-name}">wrapper from each fragment's HTML, so the fragment's real content becomes the direct children of the outer.widgetblock (matching the pattern already used correctly byproduct-list,compare-products,support-search, etc., which use a distinct root class likeproduct-list-widget).<script type="module" src="...">tags inarticle-center.html,press-center.html, andsearch-results.html— scripts inserted viainnerHTMLnever execute in the browser, so these were inert markup left over from copy-paste; the module is already loaded viawidget.js's dynamicimport().sales-plp.htmlhad 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:/articlesnow renders with exactly one.article-centerelement (full width, all real children present) instead of a nested pair.🤖 Generated with Claude Code