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

Prevent ActionMenu's show_button slot from rendering its content more than once #2538

Merged
merged 4 commits into from
Jan 24, 2024

Conversation

camertron
Copy link
Contributor

What are you trying to accomplish?

Providing content to ActionMenu's with_show_button slot causes a double render.

Integration

No changes necessary in production.

Risk Assessment

  • Low risk the change is small, highly observable, and easily rolled back.
  • Medium risk changes that are isolated, reduced in scope or could impact few users. The change will not impact library availability.
  • High risk changes are those that could impact customers and SLOs, low or no test coverage, low observability, or slow to rollback.

What approach did you choose and why?

The issue is that the block provided to with_show_button is forwarded to Overlay and ultimately evaluated in Overlay's view context. I made use of our shiny new evaluate_block method that evaluates blocks in their receiver's view context (i.e. the receiver of the block's binding).

Anything you want to highlight for special attention from reviewers?

I wasn't able to write a viable test using render_inline since I needed to actually run everything through the Rails render stack. I ended up adding a test helper called render_inline_erb. Would love some 👀 on it.

Accessibility

  • No new axe scan violation - This change does not introduce any new axe scan violations.

Merge checklist

  • Added/updated tests
    - [ ] Added/updated documentation
    - [ ] Added/updated previews (Lookbook)
    - [ ] Tested in Chrome
    - [ ] Tested in Firefox
    - [ ] Tested in Safari
    - [ ] Tested in Edge

Copy link

changeset-bot bot commented Jan 24, 2024

🦋 Changeset detected

Latest commit: 76f261f

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

This PR includes changesets to release 1 package
Name Type
@primer/view-components 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

@camertron camertron marked this pull request as ready for review January 24, 2024 19:52
@camertron camertron requested review from a team and jonrohan January 24, 2024 19:52
@@ -241,7 +241,9 @@ def initialize(
#
# @param system_arguments [Hash] The arguments accepted by <%= link_to_component(Primer::Alpha::Overlay) %>'s `show_button` slot.
def with_show_button(**system_arguments, &block)
@overlay.with_show_button(**system_arguments, id: "#{@menu_id}-button", controls: "#{@menu_id}-list", &block)
@overlay.with_show_button(**system_arguments, id: "#{@menu_id}-button", controls: "#{@menu_id}-list") do |button|
evaluate_block(button, &block)
Copy link
Member

Choose a reason for hiding this comment

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

wild

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hah yeah, all credit to @BlakeWilliams for figuring out the block.binding.receiver fix (which is what evaluate_block uses to work its magic).

@camertron camertron merged commit 35e5d06 into main Jan 24, 2024
30 checks passed
@camertron camertron deleted the fix_show_button_block_content branch January 24, 2024 21:14
@primer primer bot mentioned this pull request Jan 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants