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

feat(overlay): add content property for overlay-trigger performance optimization #5046

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

rubencarvalho
Copy link
Collaborator

@rubencarvalho rubencarvalho commented Jan 27, 2025

Description

This PR introduces a new content property on , allowing consumers to explicitly declare the types of overlays they intend to use. This helps optimize performance by preventing unnecessary DOM updates, reducing re-render loops, and avoiding slot reparenting issues.

Previously, dynamically determined the required overlays by checking assigned slot content. However, this approach caused unintended re-renders and, in some cases, infinite render loops due to slotchange event handling. The new content property provides a declarative alternative, allowing better control over which overlays should be rendered.

For full details, see the RFC: “content” property on <overlay-trigger>.

Related issue(s)

Motivation and context

The primary motivation for this change is to improve performance and prevent unintended re-renders caused by the current slot-based content detection in <overlay-trigger>. The existing approach dynamically determines which overlays to render by inspecting assigned slot content, but this can lead to unnecessary DOM updates, race conditions, and in some cases, infinite render loops. By introducing the content property, consumers can explicitly declare the overlay types they intend to use, reducing unnecessary computations and ensuring more predictable behavior.

This change not only improves stability but also provides a clearer, more declarative API for developers. Instead of relying on implicit slot detection, which can sometimes cause the unintended side effects, consumers can now specify their overlay needs up front. The implementation remains backwards compatible, allowing existing functionality to continue working while encouraging adoption of the more efficient approach (with development warnings when not using the new property). Over time, as adoption increases, we can consider making the content property a required part of the API to further standardize and optimize overlay behavior.

How has this been tested?

The original bug reporters tested this solution manually on their application and confirmed this does indeed solve #4689.

  • Added a new Storybook story to reflect the new property

    1. Visit story
    2. Inspect DOM
    3. Verify only the respective sp-overlay are rendered by default
  • Added integration tests to cover new functionality

    1. Tested for dev warnings
    2. Tested for backwards compatibility
    3. Tested for all combinations
  • Existing tests pass (backwards compatibility).

  • Did it pass in Desktop?

  • Did it pass in Mobile?

  • Did it pass in iPad?

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore (minor updates related to the tooling or maintenance of the repository, does not impact compiled assets)

Checklist

  • I have signed the Adobe Open Source CLA.
  • My code follows the code style of this project.
  • If my change required a change to the documentation, I have updated the documentation in this pull request.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I have reviewed at the Accessibility Practices for this feature, see: Aria Practices

Best practices

This repository uses conventional commit syntax for each commit message; note that the GitHub UI does not use this by default so be cautious when accepting suggested changes. Avoid the "Update branch" button on the pull request and opt instead for rebasing your branch against main.

Copy link

github-actions bot commented Jan 27, 2025

Branch preview

Review the following VRT differences

When a visual regression test fails (or has previously failed while working on this branch), its results can be found in the following URLs:

If the changes are expected, update the current_golden_images_cache hash in the circleci config to accept the new images. Instructions are included in that file.
If the changes are unexpected, you can investigate the cause of the differences and update the code accordingly.

Copy link

Tachometer results

Currently, no packages are changed by this PR...

Copy link

github-actions bot commented Jan 27, 2025

Lighthouse scores

Category Latest (report) Main (report) Branch (report)
Performance 0.99 0.99 0.99
Accessibility 1 1 1
Best Practices 1 1 1
SEO 1 0.92 0.92
PWA 1 1 1
What is this?

Lighthouse scores comparing the documentation site built from the PR ("Branch") to that of the production documentation site ("Latest") and the build currently on main ("Main"). Higher scores are better, but note that the SEO scores on Netlify URLs are artifically constrained to 0.92.

Transfer Size

Category Latest Main Branch
Total 248.229 kB 234.445 kB 234.177 kB 🏆
Scripts 60.559 kB 54.462 kB 54.359 kB 🏆
Stylesheet 51.555 kB 45.496 kB 45.384 kB 🏆
Document 6.239 kB 5.496 kB 5.47 kB 🏆
Font 127.046 kB 126.613 kB 🏆 126.615 kB

Request Count

Category Latest Main Branch
Total 52 52 52
Scripts 41 41 41
Stylesheet 5 5 5
Document 1 1 1
Font 2 2 2

@coveralls
Copy link
Collaborator

coveralls commented Jan 27, 2025

Pull Request Test Coverage Report for Build 13439900093

Details

  • 86 of 86 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.01%) to 98.2%

Totals Coverage Status
Change from base Build 13439649647: 0.01%
Covered Lines: 33156
Relevant Lines: 33585

💛 - Coveralls

Copy link

changeset-bot bot commented Jan 31, 2025

⚠️ No Changeset found

Latest commit: fce4db4

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@rubencarvalho rubencarvalho force-pushed the ruben/fixing-overlay-infinite-render branch from 672ea78 to 4545fe3 Compare February 5, 2025 15:47
@rubencarvalho rubencarvalho changed the title chore: always render sp-overlay feat(overlay): add content property for performance optimization Feb 6, 2025
@rubencarvalho rubencarvalho changed the title feat(overlay): add content property for performance optimization feat(overlay): add content property for overlay-trigger performance optimization Feb 6, 2025
@rubencarvalho rubencarvalho force-pushed the ruben/fixing-overlay-infinite-render branch from ecc906e to 4d9e129 Compare February 17, 2025 11:00
@rubencarvalho rubencarvalho marked this pull request as ready for review February 17, 2025 15:05
@rubencarvalho rubencarvalho requested a review from a team as a code owner February 17, 2025 15:05
@rubencarvalho rubencarvalho force-pushed the ruben/fixing-overlay-infinite-render branch from 874bb09 to 5683c09 Compare February 17, 2025 15:07
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.

[Bug]: OverlayTrigger can get stuck in a render loop causing page crash
2 participants