Repository navigation
[Blazor] Document DOM listener lifecycle ownership - #68823
Merged
PureWeen merged 2 commits intoSep 2, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds Components-area guidance on owning and cleaning up JavaScript event listeners when the target DOM can be replaced (e.g., during prerender-to-interactive transition or enhanced navigation), with an emphasis on using the narrowest viable lifecycle boundary and avoiding unnecessary document/window listeners.
Changes:
- Document a Components-specific rule of thumb for DOM listener lifecycle ownership under prerendering and enhanced navigation.
- Clarify that element-scoped behavior should be owned by the narrowest durable boundary and cleaned up on removal, reserving global listeners for truly global behavior.
Show a summary per file
| File | Description |
|---|---|
| src/Components/AGENTS.md | Adds JavaScript DOM lifecycle guidance for listener ownership/cleanup under DOM replacement scenarios. |
Review details
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
- Files reviewed: 1/1 changed files
- Comments generated: 0
- Review effort level: Lite
Guide element-specific JavaScript behavior toward scoped lifecycle owners across prerender-to-interactive transitions and enhanced navigation, while preserving global listeners for genuinely global behavior. Co-authored-by: Copilot App <[email protected]>
Require lifecycle-sensitive tests to exercise the render boundary that owns the relevant DOM, and route template-owned behavior to the existing generated-template browser tests. Co-authored-by: Copilot App <[email protected]>
PureWeen
force-pushed
the
pureween-codify-blazor-lifecycle-guidance
branch
from
August 27, 2026 14:33
9aab4ec to
df59f5e
Compare
dariatiurina
approved these changes
Aug 31, 2026
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.
Summary
Rationale
#68677 exposed a listener attached once to prerendered menu DOM that was later replaced by the interactive renderer. Both #68768 and the first revision of #68809 reached for document-level delegation. Maintainer feedback on #68768 explicitly rejected a global listener for element-specific behavior and requested the narrowest practical scope.
The current #68809 direction uses custom-element connection and disconnection callbacks, matching the lifecycle-owned pattern already used by Blazor client validation in #67324.
The regression-test investigation exposed a related boundary issue: the template test matrix defaults to per-page interactivity, which can leave the surrounding layout and navigation menu static even when the selected page is interactive. An explicit all-interactive row was required to prove that the target DOM was replaced. Permanent coverage also belongs in the existing generated-template browser tests because the behavior is owned by generated template content.
The guidance remains intentionally scoped to Components. It does not require every listener to use a custom element, every lifecycle test to use global interactivity, or every template-related behavior to move out of Components E2E; those choices follow the ownership boundary of the specific behavior under test.