feat: add formbricks.on/off event subscriptions, forwarded to the SDK before setup [ENG-1814] - #54
Open
pandeymangg wants to merge 2 commits into
Open
feat: add formbricks.on/off event subscriptions, forwarded to the SDK before setup [ENG-1814]#54pandeymangg wants to merge 2 commits into
pandeymangg wants to merge 2 commits into
Conversation
… before setup [ENG-1814]
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Team Run ID: 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. Comment |
|
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.



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
undefinedfor npm users. This addsformbricks.on(event, handler)/off(event, handler)with typedformbricks_*event names and payloads.Two behaviours matter more than the plumbing:
setup()runs — the opposite order from the method queue, which flushes after. A subscription queued behind setup would always register too late to hearformbricks_setup_successful; this ordering is what makes it observable through the wrapper at all.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 seeformbricks_setup_successful, which a browser console can never catch.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
formbricks_setup_successfulobserved through a setup that emits, unsubscribe before load / after forwarding,off()on pending entries, and the legacy-instance warning path.instance.setup()turns the ordering test red.formbricks_setup_successful,formbricks_action_tracked,formbricks_survey_shown, bothformbricks_response_submittedemits with the persistedresponseId, andformbricks_survey_closedexactly 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