diff --git a/package-lock.json b/package-lock.json index 8ddc061..a6ab62d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3551,7 +3551,8 @@ "version": "1.3.0", "resolved": "https://registry.npmjs.org/growly/-/growly-1.3.0.tgz", "integrity": "sha1-8QdIy+dq+WS3yWyTxrzCivEgwIE=", - "dev": true + "dev": true, + "optional": true }, "har-schema": { "version": "2.0.0", @@ -5692,6 +5693,7 @@ "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", "dev": true, + "optional": true, "requires": { "yallist": "^4.0.0" } @@ -5918,6 +5920,7 @@ "resolved": "https://registry.npmjs.org/node-notifier/-/node-notifier-8.0.1.tgz", "integrity": "sha512-BvEXF+UmsnAfYfoapKM9nGxnP+Wn7P91YfXmrKnfcYCx6VBeoN5Ez5Ogck6I8Bi5k4RlpqRYaw75pAwzX9OphA==", "dev": true, + "optional": true, "requires": { "growly": "^1.3.0", "is-wsl": "^2.2.0", @@ -5932,6 +5935,7 @@ "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.4.tgz", "integrity": "sha512-tCfb2WLjqFAtXn4KEdxIhalnRtoKFN7nAwj0B3ZXCbQloV2tq5eDbcTmT68JJD3nRJq24/XgxtQKFIpQdtvmVw==", "dev": true, + "optional": true, "requires": { "lru-cache": "^6.0.0" } @@ -5941,6 +5945,7 @@ "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", "dev": true, + "optional": true, "requires": { "isexe": "^2.0.0" } @@ -7195,7 +7200,8 @@ "version": "0.1.1", "resolved": "https://registry.npmjs.org/shellwords/-/shellwords-0.1.1.tgz", "integrity": "sha512-vFwSUfQvqybiICwZY5+DAWIPLKsWO31Q91JSKl3UYv+K5c2QRPzn0qzec6QPu1Qc9eHYItiP3NdJqNVqetYAww==", - "dev": true + "dev": true, + "optional": true }, "signal-exit": { "version": "3.0.3", @@ -8069,7 +8075,8 @@ "version": "8.3.1", "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.1.tgz", "integrity": "sha512-FOmRr+FmWEIG8uhZv6C2bTgEVXsHk08kE7mPlrBbEe+c3r9pjceVPgupIfNIhc4yx55H69OXANrUaSuu9eInKg==", - "dev": true + "dev": true, + "optional": true }, "v8-compile-cache": { "version": "2.2.0", @@ -8272,7 +8279,8 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", - "dev": true + "dev": true, + "optional": true }, "yargs": { "version": "15.4.1", diff --git a/package.json b/package.json index 7e7123d..75678fd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "synks", - "version": "1.1.7", + "version": "1.1.8", "description": "Asynchronous view renderer", "main": "dist/synks.js", "types": "dist/index.d.ts", diff --git a/src/render.ts b/src/render.ts index fa70377..cc55d52 100644 --- a/src/render.ts +++ b/src/render.ts @@ -14,6 +14,13 @@ import { renderChildren } from './render-children'; import { transformNode } from './transform-node'; let updateQueue = []; +let cleanupQueue = []; + +function startCleanup() { + const cleanup = cleanupQueue.slice(); + cleanupQueue = []; + cleanup.forEach((d) => d()); +} export async function render( currentNode: VNode | VNode[], @@ -41,7 +48,9 @@ export async function render( } if (cachedTarget) { - removeNode(cachedTarget); + cleanupQueue.push(() => { + removeNode(cachedTarget); + }); } } @@ -183,6 +192,9 @@ export async function render( } const rendered = await render(output, previousTree as VNode, container, childIndex, newContext); + + startCleanup(); + if (!(currentNode instanceof Array)) { currentNode.instance = output; }