histoire
Version:
A fast story book powered by Vite
25 lines • 2.37 kB
TypeScript
/**
* Inline script defining `__histoireEntryFailed`, called when a dev document's
* module entry fails to load. A module script fires `error` when the entry or
* any of its static imports can't be fetched (a dropped connection, e.g.
* Chromium `net::ERR_NETWORK_CHANGED`); the document would otherwise stay blank.
* It reloads at most 3 times a minute per document URL, tracked in
* `sessionStorage`, and never without it; it returns whether it will reload.
* It reloads only once the server answers: a reload during the outage would
* leave the browser's error page, where nothing can recover.
*/
export declare const ENTRY_RELOAD_SCRIPT = "window.__histoireEntryFailed = function () {\n var key = '__histoire_entry_reload__:' + window.location.pathname + window.location.search\n var now = Date.now()\n var recent\n try {\n recent = JSON.parse(window.sessionStorage.getItem(key) || '[]').filter(function (time) { return now - time < 60000 })\n if (recent.length >= 3) return false\n window.sessionStorage.setItem(key, JSON.stringify(recent.concat(now)))\n }\n catch (error) {\n return false\n }\n // 0.5, 1.5, 4.5 s: a brief network change can outlast the first retries.\n window.setTimeout(function () { reloadWhenReachable(0) }, 500 * Math.pow(3, recent.length))\n return true\n}\n\nfunction reloadWhenReachable(attempt) {\n // Any HTTP response means the server is reachable again; poll for up to 30 s.\n window.fetch(window.location.href, { method: 'HEAD', cache: 'no-store' }).then(function () {\n window.location.reload()\n }, function () {\n if (attempt < 60) window.setTimeout(function () { reloadWhenReachable(attempt + 1) }, 500)\n })\n}";
/**
* Inline script reloading a dev document (workbench, embed) under the same
* guard when a dynamic import outside its framework's error handling fails
* to fetch and nothing catches it. Story documents report these through the
* runtime's own error reporter instead. Requires {@link ENTRY_RELOAD_SCRIPT}.
*/
export declare const UNHANDLED_MODULE_FAILURE_SCRIPT: string;
/**
* Module entry script of a dev document, reloading it when its graph fails to load.
* Pair it with {@link ENTRY_RELOAD_SCRIPT} earlier in the document.
* @param src Entry module URL.
*/
export declare function renderModuleEntry(src: string): string;
//# sourceMappingURL=entry-reload.d.ts.map