Fix InputText binding with Shadow DOM elements#65629
Open
ilonatommy wants to merge 2 commits intodotnet:mainfrom
Open
Fix InputText binding with Shadow DOM elements#65629ilonatommy wants to merge 2 commits intodotnet:mainfrom
ilonatommy wants to merge 2 commits intodotnet:mainfrom
Conversation
When events originate from within a Shadow DOM, event.target points to the shadow host element rather than the actual input element inside the shadow root. This causes EventFieldInfo.fromEvent and parseChangeEvent to fail to identify the input element, breaking Blazor's two-way binding. Use event.composedPath()[0] instead of event.target when the event is composed (event.composed === true) to resolve the actual originating element from within the Shadow DOM. - EventFieldInfo.ts: Use composedPath()[0] for composed events in fromEvent - EventTypes.ts: Use composedPath()[0] for composed events in parseChangeEvent - E2E test: Add InputEvent_ShadowDom_RespondsOnKeystrokes test with Shadow DOM web component Fixes dotnet#60885 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
|
Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 AI Summary
📋 Automated Fix Report
🔍 Pre-Flight — Context & Validation
Issue: #60885 - [Blazor] InputText binding is not supported well with Shadow DOM elements
Area: area-blazor (
src/Components/)Key Findings
event.targetpoints to the shadow host element, not the actual<input>inside the shadow rootEventFieldInfo.fromEventandparseChangeEventto fail to identify the input element, breaking two-way bindingevent.composedPath()[0]instead ofevent.targetwhenevent.composed === trueFix Candidates
composedPath()[0]whenevent.composed === trueEventFieldInfo.ts,EventTypes.ts🧪 Test — Bug Reproduction
Test Result: ✅ TESTS CREATED
Test Type: E2E
Test Type Rationale: Bug is in JavaScript event handling within Shadow DOM — requires browser to reproduce. Team (@javiercn) specifically requested E2E tests.
Tests Written
InputEvent_ShadowDom_RespondsOnKeystrokes— Verifies that typing into an input inside a Shadow DOM web component correctly updates Blazor's bound value viaoninputeventTest Assets Created
BasicTestApp/wwwroot/js/shadowDomInput.js— Web component<shadow-dom-input>wrapping<input>in Shadow DOMBasicTestApp/ShadowDomBindingComponent.razor— Razor component using<shadow-dom-input>with@bind:event="oninput"index.htmland_ServerHost.cshtmlIndex.razor🚦 Gate — Test Verification & Regression
Gate Result:⚠️ BLOCKED (pre-existing build errors)
npm run build): ✅ PASSEDmain(unrelated to this PR)🔧 Fix — Analysis & Comparison
Fix Exploration Summary
Total Attempts: 5 + 2 cross-pollination rounds
Selected Fix: Inline ternary
event.composed ? event.composedPath()[0] : event.targetAttempt Results
getEventTarget()utility functionevent.targetvia Object.definePropertyshadowRoot.activeElementrecursivelyactiveElementmay not match the event sourcecomposedPath()for first bindable form controlComparison
Recommendation
Fix 1 is the best choice: minimal (2 lines), team-approved, standard
composedPath()API, no regression risk.