Skip to content

Fix frontend settings reset by preserving WebView cache across scene lifecycle#3863

Closed
binarylogic wants to merge 1 commit intohome-assistant:masterfrom
binarylogic:fix/webview-url-consistency
Closed

Fix frontend settings reset by preserving WebView cache across scene lifecycle#3863
binarylogic wants to merge 1 commit intohome-assistant:masterfrom
binarylogic:fix/webview-url-consistency

Conversation

@binarylogic
Copy link
Copy Markdown

Summary

Closes #3862

Fixes the long-standing issue where user frontend settings (dashboard selection, theme, sidebar configuration, timezone) periodically reset as if the app were freshly installed. This has been reported for years across iPhone, iPad, and Mac apps.

Root Cause: The app was aggressively clearing WebView cache on every scene disconnect via clearCachedControllers() in sceneDidDisconnect. Scene disconnects happen frequently during normal app lifecycle (backgrounding, multitasking, memory pressure), causing WebView recreation and loss of frontend settings stored in WebKit localStorage/IndexedDB.

Fix: Remove the unnecessary clearCachedControllers() call from scene disconnect while preserving appropriate cleanup during logout/error states via the existing onboarding observer.

Context: I'm a software engineer (Rust/Go/Ruby) but not an iOS developer. I used Claude to investigate the codebase and identify this root cause after experiencing the bug myself on multiple devices running internal-URL-only configurations.

Screenshots

N/A - Internal bug fix with no UI changes

Link to pull request in Documentation repository

Documentation: home-assistant/companion.home-assistant#N/A

Any other notes

This is a focused, surgical fix that:

  • Preserves WebView state during normal app lifecycle
  • Maintains proper cleanup on logout/error (unchanged)
  • Adds protective comment to prevent regression
  • Addresses community reports spanning multiple years and device types

The fix is conservative and low-risk - it only removes an overly aggressive cache clearing operation while leaving all legitimate cleanup paths intact.

…lifecycle

Remove clearCachedControllers() call from sceneDidDisconnect to prevent
WebView recreation during normal app lifecycle events. Scene disconnect
occurs frequently (backgrounding, multitasking, memory pressure) and
should not clear cached WebViews as this destroys frontend settings
stored in WebKit localStorage/IndexedDB.

WebView cache cleanup still occurs appropriately during logout/error
states via the onboarding observer.

Fixes periodic dashboard/theme/sidebar settings reset reported in
community for years across iPhone, iPad, and Mac apps.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link
Copy Markdown

@home-assistant home-assistant Bot left a comment

Choose a reason for hiding this comment

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

Hi @binarylogic

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@home-assistant home-assistant Bot marked this pull request as draft September 26, 2025 21:09
@home-assistant
Copy link
Copy Markdown

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Fixes the long-standing issue where user frontend settings (dashboard selection, theme, sidebar configuration, timezone) periodically reset by preventing aggressive WebView cache clearing during normal app lifecycle events.

  • Removes unnecessary clearCachedControllers() call from scene disconnect handler
  • Preserves WebView state during backgrounding, multitasking, and memory pressure events
  • Maintains proper cleanup during logout/error states via existing onboarding observer

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@bgoncal
Copy link
Copy Markdown
Member

bgoncal commented Sep 29, 2025

Cleaning cached controllers doesn't mean cleaning the webview cache, if that was the case then force closing the app would also clean the cache as the controller would be deallocated.

@bgoncal bgoncal closed this Sep 29, 2025
@bgoncal
Copy link
Copy Markdown
Member

bgoncal commented Sep 29, 2025

Feel free to reopen the PR in case I misunderstood your change or you add a different approach.

@binarylogic
Copy link
Copy Markdown
Author

@bgoncal Thanks for checking this out. This issue only occurs in the iOS app, never in the browser. When I access Home Assistant through a browser, my settings persist correctly. That makes me think this is specific to the iOS app rather than the frontend. If that’s not the case, could you point me to where I should look next?

@bgoncal
Copy link
Copy Markdown
Member

bgoncal commented Oct 5, 2025

When I saw your PR I forwarded the issue to frontend devs and requested priority in moving this settings to be persisted out of the browser (webview) domain, they will give priority to this.

@Uncloak2
Copy link
Copy Markdown

When I saw your PR I forwarded the issue to frontend devs and requested priority in moving this settings to be persisted out of the browser (webview) domain, they will give priority to this.

is there a github issue for it?

@bgoncal
Copy link
Copy Markdown
Member

bgoncal commented Oct 28, 2025

There is a PR open already home-assistant/frontend#25702

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

User settings reset randomly across iOS and Mac apps (dashboard, theme, sidebar, etc.)

4 participants