Skip to content

Commit

Permalink
clean moutables on unmount and return temp when render content
Browse files Browse the repository at this point in the history
  • Loading branch information
ECorreia45 committed Jul 20, 2024
1 parent 556a916 commit b7bb1e6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/html.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1334,7 +1334,7 @@ describe('html', () => {
setX(20)

expect(document.body.innerHTML).toBe('<span>Non Zero: 20</span>')
expect(document.body.children[0]).toEqual(n) // node should be kept
expect(document.body.children[0]).not.toEqual(n)
})

it('when nested', () => {
Expand Down
4 changes: 4 additions & 0 deletions src/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ export class HtmlTemplate {
effectUnsub()
}

for (const item of this.#mountables) {
item.unmount()
}

for (const node of this.#nodes) {
if (
node instanceof ReactiveNode ||
Expand Down
6 changes: 3 additions & 3 deletions src/utils/render-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ export const renderContent = (
content: unknown,
parentNode: HTMLElement | DocumentFragment,
cb?: (item: HtmlTemplate | Node) => void
): Node[] => {
): Array<HtmlTemplate | Node> => {
if (content instanceof HtmlTemplate) {
content.render(parentNode)
cb?.(content)
return content.nodes
return [content]
}

if (Array.isArray(content)) {
let nodes: Node[] = []
let nodes: Array<HtmlTemplate | Node> = []

for (const item of content) {
if (Array.isArray(item)) {
Expand Down

0 comments on commit b7bb1e6

Please sign in to comment.