-
Notifications
You must be signed in to change notification settings - Fork 31
chore: add an example app for browser sdk #1019
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
base: main
Are you sure you want to change the base?
Conversation
|
@launchdarkly/browser size report |
|
@launchdarkly/js-sdk-common size report |
|
@launchdarkly/js-client-sdk-common size report |
cd49047 to
1048727
Compare
|
@launchdarkly/js-client-sdk size report |
126daf7 to
d701b99
Compare
10632da to
580a21a
Compare
|
|
||
| ldclient.identify(context).catch(() => { | ||
| div.replaceChild(document.createTextNode('Error identifying client'), div.firstChild as Node); | ||
| }); |
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.
Bug: UI remains stuck when identify succeeds without flags
The identify call only has a .catch() handler without a .then() for the success case. The UI update relies entirely on the change event firing. However, the SDK only emits a change event when flag values differ from previous values. If no flags are configured in the LaunchDarkly project (or the server returns empty flags), identify succeeds but no change event fires, leaving the UI permanently stuck on "Initializing...". Adding a .then() handler that calls render() would ensure the UI updates after successful identification regardless of whether flags exist.
580a21a to
f4ad1e7
Compare
|
|
||
| ldclient.identify(context).catch(() => { | ||
| div.replaceChild(document.createTextNode('Error identifying client'), div.firstChild as Node); | ||
| }); |
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.
Bug: Identify error handling uses catch but promise never rejects
The .catch() handler on ldclient.identify(context) will never execute because the SDK's identify() method returns a promise that doesn't reject on errors. Per the SDK's documented behavior, the promise "will not be rejected" - instead, errors are returned as an LDIdentifyResult object with status: 'error'. To properly handle identify failures, the code would need to use .then() and check result.status for error conditions.
This PR will add a new browser SDK example that works with the new 4.x implementation.
I think this also addressed sdk-744
Note
Adds a new browser example app for the JS client SDK and includes it in the monorepo workspaces.
packages/sdk/browser/example):src/app.ts): initializes@launchdarkly/js-client-sdk, identifies a user context, evaluatesflagKeyviavariation, listens forchange/error, and updates page text/background accordingly.package.jsonwithtsdownbuild andstartscripts; includestsconfig.jsonandtsdown.config.tstargeting browser; simpleindex.htmlandindex.cssfor rendering.packages/sdk/browser/exampleto rootpackage.jsonworkspaceslist.Written by Cursor Bugbot for commit 22f3a41. This will update automatically on new commits. Configure here.