Skip to content

Fix ReusedInstanceError in Dropdown::Menu::Item divider rendering - #4172

Merged
joelhawksley merged 2 commits into
mainfrom
joelhawksley-potential-spork
Aug 24, 2026
Merged

joelhawksley merged 2 commits into
mainfrom
joelhawksley-potential-spork

Conversation

@joelhawksley

Copy link
Copy Markdown
Contributor

Summary

Fixes three test failures surfaced by ViewComponent/view_component#2691 (which enforces single-use component instances via ViewComponent::ReusedInstanceError):

  • Primer::Alpha::Dropdown::MenuTest#test_renders_dividers
  • Primer::Alpha::Dropdown::MenuTest#test_renders_as_list
  • PrimerAlphaDropdownTest#test_renders_dropdown_with_divider

Root cause

In Primer::Alpha::Dropdown::Menu::Item#call, the divider branch was missing an early return, so a single Primer::BaseComponent instance was rendered twice — first as the divider, then again with a content block:

render(component) if divider?
render(component) { content }

This has always been latently wrong (the second render was invoked even for dividers), but was harmless until view_component started rejecting reused instances.

Fix

Add return to the divider branch so the divider is rendered exactly once and the content branch is skipped.

When rendering a divider item, the component was rendered twice—once for
the divider branch and once for the content branch—because the divider
branch was missing an early return. This produced a ViewComponent::ReusedInstanceError
under view_component >= 4.x, which enforces single-use component instances.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@joelhawksley
joelhawksley requested a review from a team as a code owner August 24, 2026 17:35
@joelhawksley
joelhawksley requested review from liuliu-dev and a lite review from Copilot August 24, 2026 17:35
@changeset-bot

changeset-bot Bot commented Aug 24, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a2e1e76

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a ViewComponent::ReusedInstanceError triggered when rendering dropdown menu dividers by ensuring the divider branch returns early, preventing the same component instance from being rendered twice.

Changes:

  • Add an early return when divider? is true so divider items render exactly once.
  • Preserve existing behavior for non-divider items by continuing to render with the content block.
Show a summary per file
File Description
app/components/primer/alpha/dropdown/menu.rb Adds an early return in Dropdown::Menu::Item#call to avoid double-rendering component instances for dividers.

Review details

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

  • Files reviewed: 1/1 changed files
  • Comments generated: 0
  • Review effort level: Lite

Fixes the ReusedInstanceError occurring during the rendering of the divider in Dropdown::Menu::Item.
@joelhawksley
joelhawksley merged commit 672410d into main Aug 24, 2026
32 checks passed
@joelhawksley
joelhawksley deleted the joelhawksley-potential-spork branch August 24, 2026 22:40
@primer primer Bot mentioned this pull request Aug 24, 2026

This branch was previously deployed

1 inactive deployment
preview — a2e1e766 Deployed Aug 24, 2026 by joelhawksley via Destroy #2495
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.

3 participants