Skip to content

fix: patch additional methods so React doesnt break with template elements#9385

Merged
snowystinger merged 5 commits intomainfrom
9376
Feb 26, 2026
Merged

fix: patch additional methods so React doesnt break with template elements#9385
snowystinger merged 5 commits intomainfrom
9376

Conversation

@LFDanLu
Copy link
Member

@LFDanLu LFDanLu commented Dec 19, 2025

Closes #9376

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices

📝 Test Instructions:

Go to S2 Picker docs. Type any description in the first example's description control, it should apply without crashing

🧢 Your Project:

RSP

@LFDanLu LFDanLu marked this pull request as ready for review December 19, 2025 18:50
@rspbot
Copy link

rspbot commented Dec 19, 2025

snowystinger
snowystinger previously approved these changes Dec 21, 2025
@snowystinger
Copy link
Member

Is a test possible for this one?

@LFDanLu
Copy link
Member Author

LFDanLu commented Dec 22, 2025

I tried to make one but couldn't get it to fail in the SSR tests without the change unfortunately

Copy link
Member

@reidbarber reidbarber left a comment

Choose a reason for hiding this comment

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

I still see the issue if I navigate to another page first, then the Picker page. Doesn't happen when just loading the Picker page first though.

@LFDanLu
Copy link
Member Author

LFDanLu commented Dec 22, 2025

oh thats bizzare, didn't expect that flow to break, I'll dig

@rspbot
Copy link

rspbot commented Dec 22, 2025

enumerable: true,
value: function (node, child) {
if (this.dataset.reactAriaHidden) {
// child might not exist in this.content for some reason (stale?), add to end instead
Copy link
Member

Choose a reason for hiding this comment

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

???

In this case, what is the child and it's parent?

Copy link
Member Author

Choose a reason for hiding this comment

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

image

the child is the bottom most div, at the time of the error this.content is a document fragment with no children hence why it breaks trying to call insertBefore

Copy link
Member

Choose a reason for hiding this comment

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

oh, this seems wrong. <template> doesn't support direct children, they should be within the document fragment. That's what these overridden methods should be doing (since react doesn't handle that). So maybe we're missing another one and that's how those dives are getting there?

Copy link
Member Author

Choose a reason for hiding this comment

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

ok I did some poking around and it seems like the monkey patches about didn't trigger their reactAriaHidden route when switching pages from some arbitrary page to the Picker docs page, hence causing the original error to appear when attempting to add a description via the example controls since we had stray direct children as you noticed above. I'm not 100% sure how that happens since the aria hidden data attribute should always be there...

On the plus side, this actually fixed a couple of tests that actually inadvertently noticed that those direct children were still appearing outside the document fragment.

Copy link
Member Author

Choose a reason for hiding this comment

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

did some more digging to verify what is happening and got this:
image

The above is from adding a debugger to the patch of appendChild where we call originalAppendChild.call(this, node); aka the else statement when we detect that the template element in question doesn't have data-react-aria-hidden. However, as can be seen above the element has said attribute as part of its React props, but not in its attributes hence why we are appending the elements as direct children to the template element rather than sending them to the document fragment.

Is there a reason we have a data-react-aria-hidden check anyways? Can't we have these patches always run on any template element since direct children aren't allowed anyways?

@rspbot
Copy link

rspbot commented Feb 20, 2026

1 similar comment
@rspbot
Copy link

rspbot commented Feb 20, 2026

@rspbot
Copy link

rspbot commented Feb 20, 2026

@LFDanLu LFDanLu self-assigned this Feb 24, 2026
@LFDanLu LFDanLu moved this from 🩺 To Triage to 👀 In Review in RSP Component Milestones Feb 24, 2026
Copy link
Member

@reidbarber reidbarber left a comment

Choose a reason for hiding this comment

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

Not seeing any issues, would be good to get this in for further testing.

@rspbot
Copy link

rspbot commented Feb 25, 2026

return;
}
while (el.childNodes.length > 0) {
el.content.appendChild(el.childNodes[0]);
Copy link
Member

Choose a reason for hiding this comment

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

do we need to remove the Child node from the original location as well? does this result in it in two places?

@snowystinger snowystinger added this pull request to the merge queue Feb 26, 2026
Merged via the queue into main with commit 088e4bf Feb 26, 2026
29 checks passed
@snowystinger snowystinger deleted the 9376 branch February 26, 2026 22:59
@github-project-automation github-project-automation bot moved this from 👀 In Review to ✅ Done in RSP Component Milestones Feb 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

Error when entering a description for the Spectrum Picker

5 participants