December 1, 2022
cancel
Showing results for 
Search instead for 
Did you mean: 
Help

marqeta.destroy() how to implement

marqeta.destroy() how to implement

Barieli
New Contributor

Hi I need to reload new card using marqetajs config.

Was trying to rebuild widget :

marqeta.destroy()

the marqeta.bootstrap() again

but getting empty iFrames.

If will reload page working fine with just marqeta.bootstrap();

Is there is a way to reload widget without reloading page?

3 REPLIES 3

Eric_Chi
Marqetan

Hi!

So it sounds like you are using the correct steps to reload widgets without a page refresh. As you said, you can call marqeta.destroy() to unsubscribe from all events and then you would call marqeta.bootstrap() passing in a config object with a new clientaccesstoken. This should render new iframes with appropriate data without reloading the page.
Have you added a callback for onFailure in the configuration object? This callback gets the error as an argument and could help in debugging. Here is a link to that section in our docs
If you are following the steps with a new clientaccesstoken and are still seeing empty iframes, try adding the callback to see the error and we can debug further from there.

 

Barieli
New Contributor

Hi Eric, didn't worked, still getting same error,

When I'm calling marqeta.destroy() 

Marqeta is still in the DOM but iFrames been removed, then I'm building Marqeta config again with a new clientaccesstoken and bootstraping marqeta again

then getting error:

This error occurs when the shadow dom in enabled and marqeta fails to find the target dom element by id.

Ah thanks for the last bit of information. Marqeta.js finds  DOM elements using document.getElementById, which would not work for shadow dom elements without a reference to the shadow root unfortunately. I am not sure of your control over your current implementation, but one possibility may be to integrate your target DOM elements via Slots instead? https://developer.mozilla.org/en-US/docs/Web/API/Element/slot