fix(web): survive Blazor hydration swap in reconnect auto-reload #97
No reviewers
Labels
No labels
bug
commercial
documentation
duplicate
enhancement
feature
good first issue
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
jasoncouture/llama-shears!97
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix-reconnect-auto-reload"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Blazor replaces the SSR-rendered
ReconnectModalsubtree on hydration, so the previousMutationObserver(bound to the pre-hydration node) never saw thecomponents-reconnect-failed/components-reconnect-rejectedclass land on the live element. Move the observer up todocument.documentElement, filter toclassmutations subtree-wide, and re-resolve#components-reconnect-modalon every fire.Test plan
components-reconnect-rejected.Pull request overview
This PR updates the Blazor reconnect auto-reload script to keep working after hydration, where Blazor can replace the SSR-rendered reconnect modal subtree (breaking observers bound to the original element).
Changes:
check()function so the live#components-reconnect-modalelement is re-found each time.MutationObservertodocument.documentElementwith subtree-wideclassattribute observation to catch class flips on the hydrated element.💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
@ -19,1 +26,4 @@attributeFilter: ['class'],});check();})();The observer only listens for
attributesmutations. If Blazor swaps in a new#components-reconnect-modalelement that already has the terminal class set at insertion time (no subsequentclassattribute change),check()will never run again and the auto-reload won’t trigger. Consider also observingchildList(or otherwise triggeringcheck()on subtree replacements) so a replaced modal gets evaluated even when its class doesn’t mutate after insertion.Watching
document.documentElementforclassattribute changes subtree-wide will callcheck()on every class update anywhere in the app, which can be very frequent in Blazor-rendered UIs. To reduce overhead, consider narrowing the observation (e.g., keep a lightweightchildListobserver to detect when the reconnect modal is swapped, and attach anattributeFilter:['class']observer only to the current modal element; or filter the mutation list to cases that involve#components-reconnect-modal).