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

Change createSlots to use layout effects when registering slots #2216

Merged
merged 4 commits into from
Aug 5, 2022

Conversation

iansan5653
Copy link
Contributor

@iansan5653 iansan5653 commented Aug 4, 2022

Currently, createSlots registers slots and re-renders in asynchronous useEffect hooks. This works eventually, but I was running into strange and unpredictable edge cases where changes wouldn't take effect because the component would re-render often and in unpredictable orders.

Changing this to use useLayoutEffect fixed the problem and I think this makes more sense - we want to move the slotted content into place before the element paints, which is what useLayoutEffect will do.

Further confirming that this is the right move is the snapshot tests for components using slots - previously they were nearly empty because the snapshot was being taken before the slotted content was fully rendered. Now, the snapshots have the full correct contents.

This was previously part of #2182 but I decided to pull it into a separate PR to justify and link the snapshot updates to this change.

Screenshots

No visual changes.

Merge checklist

  • Added/updated tests
  • [ ] Added/updated documentation
  • Tested in Chrome
  • Tested in Firefox
  • Tested in Safari
  • Tested in Edge

@iansan5653 iansan5653 self-assigned this Aug 4, 2022
@iansan5653 iansan5653 requested review from a team and colebemis August 4, 2022 19:52
@changeset-bot
Copy link

changeset-bot bot commented Aug 4, 2022

🦋 Changeset detected

Latest commit: b5dbe13

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/react Patch

Not sure what this means? Click here to learn what changesets are.

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

@github-actions
Copy link
Contributor

github-actions bot commented Aug 4, 2022

size-limit report 📦

Path Size
dist/browser.esm.js 72.9 KB (-0.01% 🔽)
dist/browser.umd.js 73.27 KB (-0.01% 🔽)

@iansan5653 iansan5653 temporarily deployed to github-pages August 4, 2022 19:59 Inactive
@iansan5653 iansan5653 temporarily deployed to github-pages August 4, 2022 19:59 Inactive
Copy link
Contributor

@colebemis colebemis left a comment

Choose a reason for hiding this comment

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

Much better ✨ Thanks, @iansan5653!

@iansan5653 iansan5653 temporarily deployed to github-pages August 5, 2022 00:54 Inactive
@iansan5653 iansan5653 temporarily deployed to github-pages August 5, 2022 00:56 Inactive
Copy link
Member

@siddharthkp siddharthkp left a comment

Choose a reason for hiding this comment

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

This is really good!

@iansan5653 iansan5653 merged commit 82fd8c3 into main Aug 5, 2022
@iansan5653 iansan5653 deleted the slots-layout-effect branch August 5, 2022 13:38
@primer-css primer-css mentioned this pull request Aug 5, 2022
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.

3 participants