-
Notifications
You must be signed in to change notification settings - Fork 1k
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
feat: Revamp @formbricks/js package #2299
feat: Revamp @formbricks/js package #2299
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.
@ShubhamPalriwala thanks for this :-) Looks good!
I already talked with @pandeymangg about it: To reduce complexity I would love to remove the question side-loading from the js (now js-core) package. Can you please discuss with @pandeymangg how to make this possible in this PR? :-)
packages/browser/package.json
Outdated
@@ -0,0 +1,61 @@ | |||
{ | |||
"name": "@formbricks/js-internal", |
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.
can we name it js-core
and also use js-core
instead of browser
? :-)
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.
Or please something like js_core
. Because building it as a iife does not support -
in the module name
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.
@jonas-hoebenreich 👍 What was the reason again why you prefer the iife
format?
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.
We initially had issues with umd leaking properties to the window object (which crashed our react shop). I just checked and it seems like this is no longer the case except the surveys package adding formbricks-surveys, formbricksSurveys & DOMPurify (below my code for reference).
We know that iife works for us, so before a switch to umd we would have to evaluate it again.
var initialWindowProperties = Object.keys(window);
var j = document.createElement('script');
j.async = true;
j.defer = true;
j.src = 'https://unpkg.com/@formbricks/surveys@1.99.0/dist/index.umd.js';
document.body.appendChild(j);
function logNewWindowProperties() {
console.log("New Window Properties:");
var currentWindowProperties = Object.keys(window);
currentWindowProperties.forEach(function(prop) {
if (!initialWindowProperties.includes(prop)) {
console.log(prop);
}
});
}
j.onload = logNewWindowProperties;
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.
hey @jonas-hoebenreich, I just tested the package with iife with the same name and it worked locally! Anything else that I can test with?
packages/js/package.json
Outdated
@@ -42,14 +42,8 @@ | |||
"@babel/core": "^7.24.0", |
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.
Can you please recheck what packages we need; I think we don't need the babel packages. I think we only need vite
, terser
& vite-plugn-dts
packages/browser/package.json
Outdated
}, | ||
"author": "Formbricks <hola@formbricks.com>", | ||
"devDependencies": { | ||
"@babel/core": "^7.24.0", |
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.
Can you please recheck what packages we need; I think we don't need the babel packages & cross-env
.
packages/browser/vite.config.ts
Outdated
const isDevelopment = mode === "dev"; | ||
const formbricksSurveysScriptSrc = isDevelopment | ||
? "http://localhost:3003/index.umd.js" | ||
: `https://unpkg.com/@formbricks/surveys@~${surveysPackageJson.version}/dist/index.umd.js`; |
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.
Also the surveys package is currently still loaded from unpkg. This should also be loaded from the formbricks api endpoint :-)
packages/browser/package.json
Outdated
@@ -0,0 +1,61 @@ | |||
{ | |||
"name": "@formbricks/js-internal", |
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.
Or please something like js_core
. Because building it as a iife does not support -
in the module name
…sage on old /api/js
…script-from-formbricks-server
…shubham/for-1993-rebuild-js-package-to-pull-script-from-formbricks-server
…for-1993-rebuild-js-package-to-pull-script-from-formbricks-server
The api/js endpoint currently still has the following problem: |
…script-from-formbricks-server
…dow.formbricks from demo to avoid infitnite loop
@@ -2,12 +2,12 @@ | |||
<script type="text/javascript"> | |||
!(function () { | |||
var t = document.createElement("script"); | |||
(t.type = "text/javascript"), (t.async = !0), (t.src = "./dist/index.umd.js"); | |||
(t.type = "text/javascript"), (t.async = !0), (t.src = "http://localhost:3000/api/packages/js-core"); |
Check warning
Code scanning / CodeQL
Inclusion of functionality from an untrusted source Medium
What does this PR do?
@formbricks/js
to@formbricks/browser
@formbricks/js
now that/api/js
endpoint.formbricks.<commands>
towindow.formbricks.<command>
to support future compatibilityFixes #2104
How should this be tested?
Run the stack locally, give the demo app or any other js package using app a try, Monitor the console logs & network tab.
Checklist
Required
pnpm build
console.logs
git pull origin main
Appreciated