feat(islands): dispose only the islands under a scope
Merged
KI
11d ago+106+106+012345678901234567890123456789-6-6-0123456789
Problem
createIslandRuntime().dispose() unmounts every island on the page. A framework that swaps part of the page on navigation (Farm's renderer islands, RFC 0012) has to dispose the outgoing part only, and keep the islands in a layout it keeps running.
Change
dispose(scope?: ParentNode): unmounts the islands underscope, and aborts the ones there still waiting for their strategy.- Islands already removed from the document go too, wherever they were.
- Without a scope it disposes every island, as before.
- README:
hydrate(scope)/dispose(scope)for a navigation.
Verification
pnpm typecheck,pnpm lint,pnpm format:check: cleanpnpm test: 265 passed, 22 files (3 new: disposes only the scope, hydrates a scope again after disposing it, drops a waiting island when its scope is disposed)pnpm build: ok- Farm's leaf example e2e on this build (local link): 14 passed in dev and production, including navigating away from an islands page and back
Not run: pnpm test:e2e (CI runs it).
Summary by cubic
Lets a framework that swaps part of the page on navigation dispose only the outgoing scope, so the islands outside it keep running. dispose(scope) now unmounts and aborts islands under scope only, including islands already removed from the document; without a scope it disposes every island as before.
- Adds
dispose(scope)alongside the existinghydrate(scope), so a navigation can dispose the replaced part and hydrate the new one without touching the rest.