-
Notifications
You must be signed in to change notification settings - Fork 914
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
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 2 Ignored Deployments
|
Thank you for following the naming conventions for pull request titles! 🙏 |
There was a problem hiding this 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:
packages/js/src/website.ts
Outdated
console.error("🧱 Formbricks - Global error: You need to pass the apiHost as the first argument"); | ||
if (prop === "init") { | ||
// if still initializing, return | ||
if (isInitializing) { |
There was a problem hiding this comment.
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"
- if initializing
- else:
- add to queue + process queue
packages/js/src/website.ts
Outdated
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)( |
There was a problem hiding this comment.
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)
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?
Checklist
Required
pnpm build
console.logs
git pull origin main
Appreciated