feat(console-web): add bounded iframe keep-alive
- opt service and settings pages into document retention - preserve iframe identity and local Solid state across navigation - cap retained documents with deterministic LRU eviction - deliver activate, deactivate, and dispose lifecycle messages - reject commands emitted by inactive page documents - expose page activity as a Solid accessor - test retention, recreation, eviction, and invalid limits
This commit is contained in:
@@ -6,12 +6,13 @@ import { notifyReady, sendCommand } from "../sdk/page";
|
||||
/**
|
||||
* Connects one iframe document to the persistent Host Shell.
|
||||
*
|
||||
* The listener and state belong to the iframe's Solid owner. Navigating or
|
||||
* removing the iframe runs `onCleanup`, so the old document cannot continue to
|
||||
* receive Host snapshots.
|
||||
* A keep-alive document remains mounted while inactive and exposes that state
|
||||
* through `active`. Removing the iframe still runs `onCleanup`, so an evicted
|
||||
* document cannot continue to receive Host snapshots.
|
||||
*/
|
||||
export function createFrameBridge(view: View) {
|
||||
const [state, setState] = createSignal<HostSharedState | null>(null);
|
||||
const [active, setActive] = createSignal(false);
|
||||
|
||||
const receive = (event: MessageEvent<unknown>) => {
|
||||
if (event.origin !== window.location.origin || event.source !== window.parent) return;
|
||||
@@ -19,8 +20,15 @@ export function createFrameBridge(view: View) {
|
||||
if (event.data.type === "state" && event.data.state.view === view) {
|
||||
setState(event.data.state);
|
||||
}
|
||||
if (event.data.type === "dispose") {
|
||||
window.dispatchEvent(new Event("wasmeld:dispose"));
|
||||
if (event.data.type === "lifecycle") {
|
||||
const phase = event.data.phase;
|
||||
setActive(phase === "activate");
|
||||
window.dispatchEvent(
|
||||
new CustomEvent("wasmeld:lifecycle", {
|
||||
detail: { phase },
|
||||
}),
|
||||
);
|
||||
window.dispatchEvent(new Event(`wasmeld:${phase}`));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -33,6 +41,7 @@ export function createFrameBridge(view: View) {
|
||||
|
||||
return {
|
||||
state,
|
||||
active,
|
||||
command(command: PageCommand) {
|
||||
sendCommand(view, command);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user