Skip to content

feat: add formbricks.on/off event subscriptions, forwarded to the SDK before setup [ENG-1814] - #54

Open
pandeymangg wants to merge 2 commits into
mainfrom
anshuman/eng-1814-events-api
Open

feat: add formbricks.on/off event subscriptions, forwarded to the SDK before setup [ENG-1814]#54
pandeymangg wants to merge 2 commits into
mainfrom
anshuman/eng-1814-events-api

Conversation

@pandeymangg

Copy link
Copy Markdown
Contributor

What & why

The published wrapper forwards a hard-coded method list, so the new event API shipping in js-core (formbricks/formbricks#9133, ENG-1814) would be undefined for npm users. This adds formbricks.on(event, handler) / off(event, handler) with typed formbricks_* event names and payloads.

Two behaviours matter more than the plumbing:

  1. Subscriptions are forwarded to the SDK BEFORE setup() runs — the opposite order from the method queue, which flushes after. A subscription queued behind setup would always register too late to hear formbricks_setup_successful; this ordering is what makes it observable through the wrapper at all.
  2. The unsubscribe returned by on() works across the load boundary — taken before the SDK script loads, it removes the pending entry; taken after, it reaches the real registry. off() covers both states too.

Also feature-detects older self-hosted instances whose js-core predates events: a console warning instead of a crash, and the rest of the SDK keeps working.

The playground gains an "Events" panel that subscribes to all five events before setup() — the permanent way to see formbricks_setup_successful, which a browser console can never catch.

⚠️ Merge order

Do not merge/release before the js-core side ships (formbricks/formbricks#9133 → epic → release). Until then a published wrapper would only ever hit the older-instance warning path.

How this was tested

  • Unit: 47/47 ✅ — six new tests: the flush-before-setup ordering (asserted mechanically via mock invocation order), formbricks_setup_successful observed through a setup that emits, unsubscribe before load / after forwarding, off() on pending entries, and the legacy-instance warning path.
  • Ordering revert-check: moving the flush after instance.setup() turns the ordering test red.
  • Live run against a local Formbricks (localhost:3000) through the playground: all five events captured on the page panel — formbricks_setup_successful, formbricks_action_tracked, formbricks_survey_shown, both formbricks_response_submitted emits with the persisted responseId, and formbricks_survey_closed exactly once after the ending card auto-closed.
  • pnpm build, check-types ✅; biome clean on the touched files.

Linear: https://linear.app/formbricks/issue/ENG-1814 · release checklist: ENG-1850

@coderabbitai

coderabbitai Bot commented Sep 3, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Team

Run ID: 28a364e1-4497-4f6c-8a71-392a3bdf85d9


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pandeymangg
pandeymangg requested a review from Dhruwang September 3, 2026 05:11
@sonarqubecloud

sonarqubecloud Bot commented Sep 3, 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.

1 participant