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

fix: loading of onfido script upon component mount #12811

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -140,26 +140,25 @@ const OnfidoSdkViewContainer = observer(

const loadOnfidoSdkScript = React.useCallback(
(token: string) => {
const onfido_script_node = document.getElementById('onfido_sdk');
document.getElementById('onfido_sdk')?.remove();
document.getElementById('onfido_style')?.remove();

// check if the onfido sdk script has been loaded, and if its still loading the onfido script, don't re-attempt to load the script again
if (!onfido_script_node) {
const script_node = document.createElement('script');
const link_node = document.createElement('link');
const script_node = document.createElement('script');
const link_node = document.createElement('link');

script_node.id = 'onfido_sdk';
script_node.src = 'https://assets.onfido.com/web-sdk-releases/latest/onfido.min.js';
link_node.href = 'https://assets.onfido.com/web-sdk-releases/latest/style.css';
link_node.rel = 'stylesheet';
script_node.id = 'onfido_sdk';
script_node.src = 'https://assets.onfido.com/web-sdk-releases/latest/onfido.min.js';
link_node.href = 'https://assets.onfido.com/web-sdk-releases/latest/style.css';
link_node.rel = 'stylesheet';
link_node.id = 'onfido_style';

document.body.appendChild(script_node);
document.body.appendChild(link_node);
document.body.appendChild(script_node);
document.body.appendChild(link_node);

script_node.addEventListener('load', () => {
initOnfido(token);
});
} else {
script_node.addEventListener('load', () => {
initOnfido(token);
}
});
},
[initOnfido]
);
Expand Down Expand Up @@ -189,15 +188,7 @@ const OnfidoSdkViewContainer = observer(
} else if (isError) {
handleError(error as TAPIError);
}
}, [
error,
initOnfido,
isError,
is_onfido_loaded,
isSuccess,
loadOnfidoSdkScript,
service_token?.onfido?.token,
]);
}, [error, isError, isSuccess, is_onfido_loaded, loadOnfidoSdkScript, service_token?.onfido?.token]);

React.useEffect(() => {
/**
Expand Down