@paypal/react-paypal-js
Advanced tools
Comparing version 5.1.1 to 5.1.2
@@ -5,2 +5,8 @@ # Changelog | ||
### [5.1.2](https://github.com/paypal/react-paypal-js/compare/v5.1.1...v5.1.2) (2021-04-02) | ||
### Bug Fixes | ||
- prevent script provider from loading more than one sdk script ([8d5dbb7](https://github.com/paypal/react-paypal-js/commit/8d5dbb709082bec45835336a0e04312fcc9c5e1e)) | ||
### [5.1.1](https://github.com/paypal/react-paypal-js/compare/v5.1.0...v5.1.1) (2021-03-30) | ||
@@ -7,0 +13,0 @@ |
@@ -279,5 +279,9 @@ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } | ||
case "resetOptions": | ||
// destroy existing script to make sure only one script loads at a time | ||
destroySDKScript(state.options["data-react-paypal-script-id"]); | ||
return { | ||
loadingStatus: SCRIPT_LOADING_STATE.PENDING, | ||
options: action.value | ||
options: _objectSpread(_objectSpread({}, action.value), {}, { | ||
"data-react-paypal-script-id": "".concat(getNewScriptID()) | ||
}) | ||
}; | ||
@@ -292,2 +296,15 @@ | ||
function getNewScriptID() { | ||
return "react-paypal-js-".concat(Math.random().toString(36).substring(7)); | ||
} | ||
function destroySDKScript(reactPayPalScriptID) { | ||
var scriptNode = document.querySelector("script[data-react-paypal-script-id=\"".concat(reactPayPalScriptID, "\"]")); | ||
if (scriptNode === null) return; | ||
if (scriptNode.parentNode) { | ||
scriptNode.parentNode.removeChild(scriptNode); | ||
} | ||
} | ||
function usePayPalScriptReducer() { | ||
@@ -317,3 +334,5 @@ var scriptContext = useContext(ScriptContext); | ||
var initialState = { | ||
options: options, | ||
options: _objectSpread(_objectSpread({}, options), {}, { | ||
"data-react-paypal-script-id": "".concat(getNewScriptID()) | ||
}), | ||
loadingStatus: SCRIPT_LOADING_STATE.PENDING | ||
@@ -320,0 +339,0 @@ }; |
@@ -261,5 +261,10 @@ 'use strict'; | ||
case "resetOptions": | ||
// destroy existing script to make sure only one script loads at a time | ||
destroySDKScript(state.options["data-react-paypal-script-id"]); | ||
return { | ||
loadingStatus: SCRIPT_LOADING_STATE.PENDING, | ||
options: action.value, | ||
options: { | ||
...action.value, | ||
"data-react-paypal-script-id": `${getNewScriptID()}`, | ||
}, | ||
}; | ||
@@ -271,2 +276,13 @@ default: { | ||
} | ||
function getNewScriptID() { | ||
return `react-paypal-js-${Math.random().toString(36).substring(7)}`; | ||
} | ||
function destroySDKScript(reactPayPalScriptID) { | ||
const scriptNode = document.querySelector(`script[data-react-paypal-script-id="${reactPayPalScriptID}"]`); | ||
if (scriptNode === null) | ||
return; | ||
if (scriptNode.parentNode) { | ||
scriptNode.parentNode.removeChild(scriptNode); | ||
} | ||
} | ||
function usePayPalScriptReducer() { | ||
@@ -289,3 +305,6 @@ const scriptContext = React.useContext(ScriptContext); | ||
const initialState = { | ||
options, | ||
options: { | ||
...options, | ||
"data-react-paypal-script-id": `${getNewScriptID()}`, | ||
}, | ||
loadingStatus: SCRIPT_LOADING_STATE.PENDING, | ||
@@ -292,0 +311,0 @@ }; |
import React, { FunctionComponent } from "react"; | ||
import type { PayPalScriptOptions } from "@paypal/paypal-js/types/script-options"; | ||
export interface ReactPayPalScriptOptions extends PayPalScriptOptions { | ||
"data-react-paypal-script-id": string; | ||
} | ||
declare enum SCRIPT_LOADING_STATE { | ||
@@ -9,3 +12,3 @@ PENDING = "pending", | ||
interface ScriptContextDerivedState { | ||
options: PayPalScriptOptions; | ||
options: ReactPayPalScriptOptions; | ||
isPending: boolean; | ||
@@ -20,3 +23,3 @@ isRejected: boolean; | ||
type: "resetOptions"; | ||
value: PayPalScriptOptions; | ||
value: ReactPayPalScriptOptions; | ||
}; | ||
@@ -23,0 +26,0 @@ declare type ScriptReducerDispatch = (action: ScriptReducerAction) => void; |
{ | ||
"name": "@paypal/react-paypal-js", | ||
"version": "5.1.1", | ||
"version": "5.1.2", | ||
"description": "React components for the PayPal JS SDK", | ||
@@ -52,4 +52,4 @@ "keywords": [ | ||
"@babel/preset-typescript": "^7.13.0", | ||
"@commitlint/cli": "^12.0.1", | ||
"@commitlint/config-conventional": "^12.0.1", | ||
"@commitlint/cli": "^12.1.1", | ||
"@commitlint/config-conventional": "^12.1.1", | ||
"@rollup/plugin-babel": "^5.3.0", | ||
@@ -59,6 +59,6 @@ "@rollup/plugin-node-resolve": "^11.2.1", | ||
"@rollup/plugin-typescript": "^8.2.1", | ||
"@storybook/addon-actions": "^6.1.21", | ||
"@storybook/addon-essentials": "^6.1.21", | ||
"@storybook/addon-links": "^6.1.21", | ||
"@storybook/react": "^6.1.21", | ||
"@storybook/addon-actions": "^6.2.1", | ||
"@storybook/addon-essentials": "^6.2.1", | ||
"@storybook/addon-links": "^6.2.1", | ||
"@storybook/react": "^6.2.1", | ||
"@storybook/storybook-deployer": "^2.8.7", | ||
@@ -74,3 +74,2 @@ "@testing-library/react": "^11.2.6", | ||
"eslint-plugin-react": "^7.23.1", | ||
"http-server": "^0.12.3", | ||
"husky": "^6.0.0", | ||
@@ -77,0 +76,0 @@ "jest": "^26.6.3", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
80517
36
1290