Fix #149: guard null Home Assistant root before accessing shadowRoot (Firefox crash)#157
Open
program-the-brain-not-the-heartbeat wants to merge 1 commit into
Conversation
updateStyling() (the window 'resize' handler) and watchLocationChange()
dereferenced getRoot().shadowRoot without a null check. When a resize or
location-change fires while Home Assistant's DOM is mid-render — a timing
race Firefox hits intermittently — getRoot() returns null and it throws
'TypeError: can't access property "shadowRoot", s is null', leaving the
sidebar not full-width. Now bails out like buildSidebar()/getHeaderHeightPx().
Also:
- Close the unterminated 'case call-service' block (missing break;/}), which
left 'case service-js' illegally nested and broke 'npm run build' (TS1128);
rebuilt dist.
- Fix footer detection: querySelector('ch-footer' || querySelector('app-footer'))
queried a literal string; corrected to a proper || fallback.
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.
Fixes #149
The crash
On Firefox,
sidebar-cardintermittently throws:…and the sidebar stops rendering at full width.
Cause:
updateStyling()(thewindowresizehandler registered insubscribeEvents) andwatchLocationChange()callgetRoot()and then dereferenceroot.shadowRootwithout a null check. When aresizeorlocation-changedevent fires while Home Assistant's DOM is mid-render — a timing race Firefox hits more often than Chromium —getRoot()returnsnulland the access throws, aborting the styling pass (so the sidebar isn't full width).Fix: bail out early when
root/root.shadowRootaren't ready, mirroring the guards that already exist inbuildSidebar()andgetHeaderHeightPx().Also in this PR
While fixing the above I ran into two pre-existing issues:
npm run build→ TS1128). Thecase 'call-service':block opened a{but was never closed (missingbreak;/}), leavingcase 'service-js':illegally nested — so the currentsrcdoesn't compile and the committeddistpredates it. I closed the block (which also fixes the unintended fall-through fromcall-serviceintoservice-js) so the project builds again, and rebuiltdist.root.shadowRoot.querySelector('ch-footer' || root.shadowRoot.querySelector('app-footer'))put the||inside the selector string, so it always queried the literal'ch-footer'and never fell back toapp-footer. Corrected to a real||fallback.Changes
src/sidebar-card.ts— null guards inupdateStyling()+watchLocationChange(); close thecall-serviceswitch block; footer selector fix.dist/sidebar-card.js— rebuilt.Verified
npm run buildnow succeeds and the guard is present in the emitteddist.