Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion packages/solid/web/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export function Portal<T extends boolean = false, S extends boolean = false>(pro
insert(renderRoot, content);
el.appendChild(container);
props.ref && (props as any).ref(container);
onCleanup(() => el.removeChild(container));
onCleanup(() => el.contains(container) && el.removeChild(container));
}
},
undefined,
Expand Down
18 changes: 18 additions & 0 deletions packages/solid/web/test/portal.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,24 @@ describe("Testing a Portal with Synthetic Events", () => {
test("dispose", () => disposer());
});

describe("Testing a Portal whose mount is externally cleared before disposal", () => {
let div = document.createElement("div"),
disposer: () => void;
const testMount = document.createElement("div");
const Component = () => <Portal mount={testMount}>Hi</Portal>;

test("Create portal", () => {
disposer = render(Component, div);
expect((testMount.firstChild as HTMLDivElement).innerHTML).toBe("Hi");
});

test("dispose does not throw when mount has been externally emptied", () => {
// Simulate an external actor clearing the mount node (e.g. innerHTML = "")
testMount.innerHTML = "";
expect(() => disposer()).not.toThrow();
});
});

describe("Testing a Portal with direct reactive children", () => {
let div = document.createElement("div"),
disposer: () => void,
Expand Down
Loading