Skip to content

Commit

Permalink
don't remove root element from the DOM on destroy (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
merlinfuchs authored Jun 20, 2024
1 parent ac0d422 commit 0fe2d34
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/sdk/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ export function setWidgetRootStyles(el: HTMLElement) {
sinas(el, "borderRadius", "4px");
}

/**
* @internal
*/
export function removeWidgetRootStyles(el: HTMLElement) {
el.removeAttribute("style");
}

export function runOnDocumentLoaded(func: () => any) {
if (document.readyState !== "loading") {
func();
Expand Down
8 changes: 5 additions & 3 deletions src/sdk/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
createWidgetPlaceholder,
} from "./create.js";
import { EnvelopedMessage, Message, RootSignalsGetMessage, ToAgentMessage, ToRootMessage } from "../types/messages.js";
import { findCaptchaElements, setWidgetRootStyles } from "./dom.js";
import { findCaptchaElements, removeWidgetRootStyles, setWidgetRootStyles } from "./dom.js";
import { flatPromise } from "../util/flatPromise.js";
import { WidgetHandle } from "./widgetHandle.js";
import { Store } from "./persist.js";
Expand Down Expand Up @@ -311,7 +311,7 @@ export class FriendlyCaptchaSDK {
const newWidgets: WidgetHandle[] = [];
for (let index = 0; index < elements.length; index++) {
const hElement = elements[index] as HTMLElement;
if (hElement && !(hElement as any ).frcWidget) {
if (hElement && !(hElement as any).frcWidget) {
const ds = hElement.dataset;
const opts: CreateWidgetOptions = {
element: hElement,
Expand Down Expand Up @@ -352,7 +352,9 @@ export class FriendlyCaptchaSDK {
send({ type: "root_destroy_widget" });
this.bus.removeTarget(widgetId);
this.widgets.delete(widgetId);
opts.element.remove();

opts.element.innerHTML = "";
removeWidgetRootStyles(opts.element);
},
onReset: () => {
send({ type: "root_reset_widget" });
Expand Down

0 comments on commit 0fe2d34

Please sign in to comment.