Skip to content

fix: stop clearing the app's WebView cache and local storage [ENG-7679] - #100

Open
mattinannt wants to merge 2 commits into
release/1.3from
claude/awesome-lovelace-qrg4d7
Open

mattinannt wants to merge 2 commits into
release/1.3from
claude/awesome-lovelace-qrg4d7

Conversation

@mattinannt

Copy link
Copy Markdown
Member

Fixes ENG-7679

What & why

Before every survey, hardenAndLoad in packages/formbricks/lib/src/widgets/default_webview_host.dart called controller.clearCache() and controller.clearLocalStorage().

  • Android: both calls affect the whole app. clearCache() runs WebView.clearCache(true) and clearLocalStorage() runs WebStorage.deleteAllData().
  • iOS: both calls clear the shared default WKWebsiteDataStore.

As a result, the host app's own web content lost its cache and local storage every time a survey opened, and our renderer was downloaded again for every survey.

This PR removes both calls. The web SDK has never cleared anything before showing a survey, so the renderer doesn't need a clean store. The other hardening steps stay:

  • Android file and content access are still disabled.
  • The page still has no baseUrl, so it gets an opaque origin.
  • Navigation is still allowlisted.

Why this targets release/1.3: the ticket asks for 1.3.2 to ship from release/1.3. main needs Dart 3.12 / Flutter 3.44, so a release from main would leave apps on older Flutter stuck at 1.3.1. On main, #99 (ENG-7738) already removes these calls as part of the SDK Core shell.

Rejected alternative: clearing only the survey's own store. Android has no per-WebView store, so there is nothing narrower to clear.

Seam: _hardenAndLoad is now hardenAndLoad, marked @visibleForTesting, so a unit test can call it with a mocked WebViewController. It is not exported from lib/formbricks.dart, so the public API is unchanged.

Other changes in this PR:

  • The comment in sonar-project.properties listed cache/local-storage clearing as one of the WebView protections. It now lists what is actually there. The rules it suppresses are unchanged.
  • The header comment of the host file now mentions that hardenAndLoad is tested.

Testing

  • New tests in default_webview_host_test.dart, in a hardenAndLoad group:
    • The survey loads, and neither clearCache nor clearLocalStorage is called. This test fails on release/1.3: I ran it against the 1.3 source with only the rename applied (hardenAndLoad loads the survey without clearing the app's WebView data).
    • Android file and content access are still disabled, in order, before the load.
    • A load failure still reaches onError.
  • Commands (Flutter 3.47.7 from .fvmrc):
    • make format-check: 0 files changed
    • make analyze-ci: No issues found
    • make test: SUCCESS
  • End to end: a container has no device or emulator, so the end-to-end evidence is the unit test plus the CI e2e run on this PR.

Risk

  • Two-way door: the change only removes two calls, and reverting it is trivial.
  • Blast radius: every survey WebView in 1.3.x. After this change, data the renderer writes to the WebView store stays between surveys, the same as in the web SDK.

Open gaps

  • No version bump yet: 1.3.2 needs the usual separate chore: bump to 1.3.2 PR (version and CHANGELOG entry), then a release from release/1.3. Releasing is left to a human.

Generated by Claude Code

Before every survey the SDK called clearCache() and clearLocalStorage().
On Android both are app-wide (WebView.clearCache(true) and
WebStorage.deleteAllData()); on iOS they clear the shared default data
store. The host app's own web content lost its data and the renderer was
downloaded again for every survey. The web SDK never clears anything
before a survey, so the renderer does not need a clean store.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_011A96cyBk23EVBB8UX5pL97
Also drop the Sonar comment's claim that the host clears cache and local
storage, and name hardenAndLoad in the host's coverage note.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_011A96cyBk23EVBB8UX5pL97
@mattinannt
mattinannt requested a review from Dhruwang December 5, 2026 06:17
@sonarqubecloud

sonarqubecloud Bot commented Dec 5, 2026

Copy link
Copy Markdown

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants