Skip to content

fix(core/ui): guard against string-only messages in the error pill - #5390

Draft
marcoscaceres with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-respec-pill-error
Draft

fix(core/ui): guard against string-only messages in the error pill#5390
marcoscaceres with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-respec-pill-error

Conversation

Copilot AI commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Clicking the error/warning pill to view details crashed when a message was a plain string instead of an object, since string messages produce a DocumentFragment with only text nodes (firstElementChild/lastElementChild are both null).

Root cause

  • createWarnButton in src/core/ui.js unconditionally accessed fragment.firstElementChild.childNodes when firstElementChild === lastElementChild, which is also true (null === null) for text-only fragments, causing a TypeError on click.

Fix

  • Added a null guard so the "single element" shortcut only applies when firstElementChild actually exists; string messages now fall through to the existing "take everything" branch, appending the raw text fragment to the list item.
if (
  fragment.firstElementChild &&
  fragment.firstElementChild === fragment.lastElementChild
) {
  li.append(...fragment.firstElementChild.childNodes);
} else {
  li.appendChild(fragment);
}

Tests

  • Added a regression test in tests/spec/core/ui-spec.js that raises a string error, clicks the pill, and asserts the modal list renders the message without throwing.

Copilot AI linked an issue Aug 11, 2026 that may be closed by this pull request
@marcoscaceres

Copy link
Copy Markdown
Contributor

@copilot can you fix the CI issue related to the title of the PR?

Copilot AI changed the title [WIP] Fix respec pill not displaying list for string errors Fix crash when clicking error/warning pill for string messages Aug 11, 2026
Copilot AI requested a review from marcoscaceres August 11, 2026 12:50

Copilot AI commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

@copilot can you fix the CI issue related to the title of the PR?

The CI check fails because the PR title doesn't follow Conventional Commits (needs a type: prefix, e.g. fix:), which amannn/action-semantic-pull-request requires. I don't have a tool to rename the PR title directly, so could you update it to something like:

fix: crash when clicking error/warning pill for string messages

That should satisfy the "Check PR title" workflow.

@marcoscaceres marcoscaceres changed the title Fix crash when clicking error/warning pill for string messages fix(core/ui): guard against string-only messages in the error pill Aug 13, 2026
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.

respec pill (error)

2 participants