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

Add setShadowRootVersionHash to force shadowRoot to update in provide… #25332

Merged
merged 5 commits into from
Jun 21, 2024

Conversation

squid-ney
Copy link
Contributor

@squid-ney squid-ney commented Jun 19, 2024

Add setShadowRootVersionHash to force shadowRoot to update in provider when version changes. The setShadowRoot doesn't cause a re-render because a ref is passed to it. This hash is a work around to force the update. This PR builds off the investigation done in this PR that points out the useShadowRoot hooks do not behave as expected.

....

Update: Instead of hash we are going to use a simple counter. The hash may affect performance. We really just need some type of simple state that can force the side-effects that setShadowRoot is not.

Hey, I just made a Pull Request!

✔️ Checklist

  • A changeset describing the change and affected packages. (more info)
  • Added or updated documentation
  • Tests for new functionality and regression tests for bug fixes
  • Screenshots attached (for UI changes)
  • All your commits have a Signed-off-by line in the message. (more info)

@github-actions github-actions bot added the area:techdocs Related to the TechDocs Project Area label Jun 19, 2024
@backstage-goalie
Copy link
Contributor

backstage-goalie bot commented Jun 19, 2024

Changed Packages

Package Name Package Path Changeset Bump Current Version
@backstage/plugin-techdocs-react plugins/techdocs-react patch v1.2.5
@backstage/plugin-techdocs plugins/techdocs patch v1.10.6

@backstage-goalie
Copy link
Contributor

Thanks for the contribution!
All commits need to be DCO signed before they are reviewed. Please refer to the the DCO section in CONTRIBUTING.md or the DCO status for more info.

@@ -102,11 +103,12 @@ export const TechDocsReaderPageContent = withTechDocsReaderProvider(
const handleAppend = useCallback(
(newShadowRoot: ShadowRoot) => {
setShadowRoot(newShadowRoot);
incShadowRootVersion();
Copy link
Contributor

Choose a reason for hiding this comment

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

My best guess is that because the shadowRoot variable points to the DOM elements when the underlying DOM changes and the setShadowRoot call compares the old and new values to see if they're different they're the same so no side-effects get triggered... So we use the counter as a proxy to trigger these.

@github-actions github-actions bot added documentation Improvements or additions to documentation area:catalog Related to the Catalog Project Area area:scaffolder Everything and all things related to the scaffolder project area and removed documentation Improvements or additions to documentation area:catalog Related to the Catalog Project Area area:scaffolder Everything and all things related to the scaffolder project area labels Jun 20, 2024
squid-ney and others added 4 commits June 20, 2024 15:16
…r when version changes.

Signed-off-by: Sydney Achinger <sydneynicoleachinger@spotify.com>
Signed-off-by: Alex Lorenzi <alorenzi@spotify.com>
Signed-off-by: Sydney Achinger <sydneynicoleachinger@spotify.com>
Signed-off-by: Alex Lorenzi <alorenzi@spotify.com>
Signed-off-by: Sydney Achinger <sydneynicoleachinger@spotify.com>
Signed-off-by: Sydney Achinger <sydneynicoleachinger@spotify.com>
Signed-off-by: Sydney Achinger <sydneynicoleachinger@spotify.com>
@squid-ney squid-ney marked this pull request as ready for review June 20, 2024 19:54
@squid-ney squid-ney requested a review from a team as a code owner June 20, 2024 19:54
Copy link

@PeaWarrior PeaWarrior 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 over the hashing due to the potential performance hit. 👍

@squid-ney squid-ney merged commit 6f1e20c into master Jun 21, 2024
28 checks passed
@squid-ney squid-ney deleted the shadowdom-provider branch June 21, 2024 14:54
Copy link
Contributor

Thank you for contributing to Backstage! The changes in this pull request will be part of the 1.29.0 release, scheduled for Tue, 16 Jul 2024.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:techdocs Related to the TechDocs Project Area
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants