Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature-16-sidebar-eager #65

Merged
merged 2 commits into from
Nov 7, 2023
Merged

Feature-16-sidebar-eager #65

merged 2 commits into from
Nov 7, 2023

Conversation

Copy link

aem-code-sync bot commented Nov 3, 2023

Hello, I'm the AEM Code Sync Bot and I will run some test suites that validate the page speed.
In case there are problems, just click the checkbox below to rerun the respective action.

  • Re-run PSI Checks

@florentin florentin changed the base branch from feature-16-sidebar to main November 3, 2023 18:30
Copy link
Collaborator

@andreituicu andreituicu left a comment

Choose a reason for hiding this comment

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

I like this approach 👍

  • We have a standalone fragment block that is reusable (and we will most likely need it again for other use-cases in the project)
  • There is no duplication in the sidebar code or hardcodings
  • Lighthouse Score is still at 100 ✅
  • The eager loading block mechanism can also be used for other usecases if we need it later.

A couple mentions above to make things a little bit more robust and we are ready to merge.

const fragmentSection = fragment.querySelector(':scope .section');
if (fragmentSection) {
block.closest('.section').classList.add(...fragmentSection.classList);
block.closest('.fragment-wrapper').replaceWith(...fragmentSection.childNodes);
Copy link
Collaborator

Choose a reason for hiding this comment

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

we need to transport the fragmentSection's data set to the target section too, to ensure that additional section metadata configs are added, but without overriding the main's section data set (e.g. data-section-status);
I'm thinking something like:

const mainSection = block.closest('.section');
mainSection.classList.add(...fragmentSection.classList);
mainSection.dataset = Object.assign({}, fragmentSection.dataset, mainSection.dataset);

const targetDivs = divs.filter(
(d) => d.textContent.trim().toLowerCase() === 'style' || d.textContent.trim().toLowerCase() === 'sidebar',
);
if (targetDivs.length !== 2) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This condition can unfortunately be broken. Take the following example which will say that there is already a sidebar and doesn't need to be autoblocked:

<div class="section-metadata">
  <div>
    <div>Style</div>
     <div>Test1</div>
  </div>
</div>

<div class="section-metadata">
  <div>
    <div>Test2</div>
     <div>Sidebar</div>
  </div>
</div>

Also the Style property can have multiple values coma separated and with spaces, e.g.:

<div class="section-metadata">
  <div>
    <div>Style</div>
     <div>Sidebar, Test1, Test2</div>
  </div>
</div>

https://github.com/hlxsites/servicenow/blob/main/scripts/aem.js#L453

So we need a condition that is a little bit more robust.

@@ -189,8 +215,22 @@ function buildAutoBlocks(main) {
}
}

function detectSidebar(main) {
export function addH3Spans(elem) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This function is not called

Copy link
Collaborator

@andreituicu andreituicu left a comment

Choose a reason for hiding this comment

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

as an exception for the usual PR review process, I'm approving and merging this PR in state that it is now, as I need the functionality for a demo today.

@florentin please create a new PR for the 2 items discussed above. I cleaned up the addH3Spans function as it was trivial.

@andreituicu andreituicu merged commit 320fc90 into main Nov 7, 2023
2 checks passed
@andreituicu andreituicu deleted the feature-16-sidebar-eager branch November 7, 2023 15:01
@andreituicu andreituicu restored the feature-16-sidebar-eager branch November 7, 2023 15:01
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.

2 participants