Error “Component could not mount. Root node was not found”
See original GitHub issueDescribe the bug
Error “Component could not mount. Root node was not found”
We are getting this error rendering the dropin component, we are using react 17.0.2
, the dropin is not showing because this error are happening several times, this is our code:
let dropin;
let dropinMountFailed = false;
const AdyenCheckout = (await import('@adyen/adyen-web')).default;
const checkout = new AdyenCheckout(configuration);
dropin = checkout.create('dropin').mount(dropinContainer.current);
try {
dropin = checkout.create('dropin').mount(dropinContainer.current);
} catch (e) {
const endPaymentRenderTime = Date.now();
const totalRenderTime = endPaymentRenderTime - startPaymentRenderTime;
dropinMountFailed = true;
}
if (dropinMountFailed) {
try {
dropin = checkout.create('dropin').mount('#dropin-payment-container');
} catch (e) {
console.log(e)
}
}
setDropin(dropin);
We are sure that the issue is on this line:
const dropin = checkout.create('dropin').mount(dropinContainer.current);
because if the dropinContainer.current
is null the error will show us.
So, we added some validations in order to render in because is wrong but it didn’t work
let dropin;
let dropinMountFailed = false;
try {
dropin = checkout.create('dropin').mount(dropinContainer.current);
} catch (e) {
const endPaymentRenderTime = Date.now();
const totalRenderTime = endPaymentRenderTime - startPaymentRenderTime;
dropinMountFailed = true;
}
if (dropinMountFailed) {
try {
dropin = checkout.create('dropin').mount('#dropin-payment-container');
} catch (e) {
console.log(e)
}
}
How can we fix this error?
NOTE: The code above is all the stuff that we are using.
Expected behavior
Never see the error Error “Component could not mount. Root node was not found”
on console and the droping component rendering successfully.
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (1 by maintainers)
Top GitHub Comments
See the example in this project:
https://github.com/adyen-examples/adyen-react-online-payments
Hope this can help you more.
I am getting the same issue and it does not matter if i use a reference or id.