Skip to content

feat: host the server-delivered mobile core (JS brain) in JavaScriptCore with native fallback - #55

Draft
pandeymangg wants to merge 1 commit into
epic/js-brainfrom
anshuman/eng-2900-ios-land-the-javascriptcore-brain-host-behind-a-config-flag
Draft

feat: host the server-delivered mobile core (JS brain) in JavaScriptCore with native fallback#55
pandeymangg wants to merge 1 commit into
epic/js-brainfrom
anshuman/eng-2900-ios-land-the-javascriptcore-brain-host-behind-a-config-flag

Conversation

@pandeymangg

Copy link
Copy Markdown
Contributor

Ref ENG-2900

What & why

Was: The survey display decision (display types, recontact days, segments, display percentage, language resolution) is compiled into the SDK; changing it requires an SDK release plus a customer app store release.

Now: setup() fetches a small JS bundle from the Formbricks server (/js/mobile/v1/core.umd.cjs), hosts it in JavaScriptCore, and track() asks it which survey to show. Any failure — no bundle, wrong protocol version, evaluation error — falls back to the untouched native logic, so behaviour without a bundle is identical to today.

First iOS PR of the JS-brain epic (targets epic/js-brain, not main). Server side: formbricks/formbricks#9152.

Where to look

  • Sources/FormbricksSDK/MobileCore/MobileCoreRuntime.swift — JSContext host, serial-queue confined, protocol-version gate
  • Sources/FormbricksSDK/MobileCore/MobileCoreLoader.swift — fetch + per-host cache, offline fallback
  • Sources/FormbricksSDK/Manager/SurveyManager.swift — brain-first track(), native path unchanged as fallback

Testing

  • 7 new tests in MobileCoreRuntimeTests (init validation, protocol rejection, state pass-through across the bridge, brain-throws fallback) run against real JavaScriptCore.
  • Full suite: 121/121 green on iPhone 17 Pro simulator.
  • End-to-end (bundle fetched from a live local server, decision logged, survey rendered incl. multi-language resolution) verified on the Android twin of this PR; the iOS runtime was verified against the same built bundle in-process.

Draft — remaining scope for ENG-2900

  • Opt-out flag on FormbricksConfig (disable remote code for enterprise policies).
  • HTTPS enforcement is intact in this diff (POC-era relaxations were dropped before commit).

Note

AI model usedclaude-fable-5, reasoning effort unknown.

@sonarqubecloud

sonarqubecloud Bot commented Sep 5, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
58.8% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

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.

1 participant