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

Set data-js-sdk-library default value #465

Merged
merged 9 commits into from
Mar 19, 2024
Merged

Set data-js-sdk-library default value #465

merged 9 commits into from
Mar 19, 2024

Conversation

nbierdeman
Copy link
Contributor

Description

In service of DTPPCPSDK-1482, this PR sets a data-js-sdk-library value for tracking library usage.

Copy link

changeset-bot bot commented Mar 15, 2024

🦋 Changeset detected

Latest commit: 9d90088

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@paypal/paypal-js Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@@ -19,6 +19,14 @@ export function loadScript(
if (typeof document === "undefined") return PromisePonyfill.resolve(null);

const { url, attributes } = processOptions(options);

if (
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefer to skip the validation on the existing value and only set it if the data attribute value is undefined. That way we can add new libraries in the future like vue-paypal-js and not have to worry about updating this code path.

    if (!attributes["data-js-sdk-library"]) {
        attributes["data-js-sdk-library"] = "paypal-js";
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, cool. I'll need to look into this, because it ends up inserting a new script in the DOM even when there's already one with the same params.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@gregjopa, I tried adding the data-js-sdk-library default value in loadScript, processOptions, loadCustomScript, and insertScriptElement, and ended up moving it back to loadScript. Definitely open to trying something else too, but marking this ready for review for now.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think you added it in the right spot in loadScript() @nbierdeman 💯

@nbierdeman nbierdeman changed the title Set data-js-sdk-library value Set data-js-sdk-library default value Mar 19, 2024
@@ -64,6 +64,10 @@ export function loadCustomScript(

const { url, attributes } = options;

if (attributes && !attributes["data-js-sdk-library"]) {
Copy link
Contributor Author

@nbierdeman nbierdeman Mar 19, 2024

Choose a reason for hiding this comment

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

loadCustomScript will always have attributes when called by react-paypal-js/paypal-js -> loadScript, but checking for attributes here, since react-paypal-js calls loadCustomScript without attributes in getBraintreeNamespace here.

@@ -13,6 +13,7 @@ <h1>Load Cached Script</h1>
const options = {
clientId: "test",
dataPageType: "checkout",
dataJsSdkLibrary: "paypal-js",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This smells funky, because dataJsSdkLibrary is not a required script option, but if we don't add it here, the "load cached script" tests fail.

@nbierdeman nbierdeman marked this pull request as ready for review March 19, 2024 20:40
@nbierdeman nbierdeman requested a review from a team as a code owner March 19, 2024 20:40
@nbierdeman nbierdeman requested a review from gregjopa March 19, 2024 20:44
@nbierdeman nbierdeman merged commit 199e978 into main Mar 19, 2024
3 checks passed
@nbierdeman nbierdeman deleted the DTPPCPSDK-1482 branch March 19, 2024 20:56
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.

3 participants