Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: formbricks init error #2633

Merged
merged 7 commits into from
May 22, 2024
Merged

fix: formbricks init error #2633

merged 7 commits into from
May 22, 2024

Conversation

pandeymangg
Copy link
Contributor

@pandeymangg pandeymangg commented May 16, 2024

What does this PR do?

Fixes formbricks/internal#184 #2671 by awaiting the promise from the init function to fulfil before calling any other function.

How should this be tested?

  • Open any page in the app and open the dev tools
  • No formbricks error should be there

Checklist

Required

  • Filled out the "How to test" section in this PR
  • Read How we Code at Formbricks
  • Self-reviewed my own code
  • Commented on my code in hard-to-understand bits
  • Ran pnpm build
  • Checked for warnings, there are none
  • Removed all console.logs
  • Merged the latest changes from main onto my branch with git pull origin main
  • My changes don't cause any responsiveness issues
  • First PR at Formbricks? Please sign the CLA! Without it we wont be able to merge it 🙏

Appreciated

  • If a UI change was made: Added a screen recording or screenshots to this PR
  • Updated the Formbricks Docs if changes were necessary

Copy link

vercel bot commented May 16, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Ignored Deployments
Name Status Preview Comments Updated (UTC)
formbricks-cloud ⬜️ Ignored (Inspect) Visit Preview May 20, 2024 5:09am
formbricks-docs ⬜️ Ignored (Inspect) Visit Preview May 20, 2024 5:09am

Copy link
Contributor

github-actions bot commented May 16, 2024

Thank you for following the naming conventions for pull request titles! 🙏

Copy link
Member

@mattinannt mattinannt left a comment

Choose a reason for hiding this comment

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

@pandeymangg thanks for the PR :-) A few small suggestions that came up while going through the code:

console.error("🧱 Formbricks - Global error: You need to pass the apiHost as the first argument");
if (prop === "init") {
// if still initializing, return
if (isInitializing) {
Copy link
Member

Choose a reason for hiding this comment

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

The js-core in this case also throws a warning that it's already initialized. I think I would like to keep this and let js-core handle this case.

So we decide the cases different on the top level here:

  • if !initialized
    • if initializing
      • add to queue
    • else:
      • it's an init call -> initialize + process queue
      • else: error "call init first"
  • else:
    • add to queue + process queue

console.error(
`🧱 Formbricks - Global error: Formbricks Website SDK does not support method ${String(prop)}`
);
return;
}

try {
return (window.formbricks[prop as FormbricksWebsiteMethods] as Function)(...args);
return ((window.formbricks as TFormbricksWebsite)[prop as FormbricksWebsiteMethods] as Function)(
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't we also add this to the queue here to avoid that commands are executed in the wrong order?
(e.g. newer request after init before requests that were queued first)

@mattinannt mattinannt added this pull request to the merge queue May 22, 2024
Merged via the queue into main with commit 48859fa May 22, 2024
13 checks passed
@mattinannt mattinannt deleted the fix/js-global-error branch May 22, 2024 12:20
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.

None yet

2 participants