Files
windmill/frontend/src/app.html
T
Ruben FiszelandClaude Opus 5.5 0ac2b61034 perf: paint a snapshot of the last home in place of the boot splash (#12158)
* perf: paint home from a per-user persisted cache while it refreshes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: keep a cached first page from offering load more after a failed refresh

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: drop expired cache entries from disk when hydrating

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* perf: render home as the last confirmed user while whoami is in flight

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* perf: hydrate the home cache at boot; file answers only under their session

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* perf: paint home's cached data in its first frame from a synchronous snapshot

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: show nothing rather than 'Loading user...' while rendering as the remembered user

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: bind the cache identity to the session that confirmed the tab's user

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: record the session confirmation before setting the user, so the cache hydrates

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* chore: cache immutable chunks on the cloudflare pages previews

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* perf: keep the cache snapshot's small entries when a large one exceeds its cap

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* perf: paint a snapshot of the last home in place of the boot splash

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: clean the home snapshot when painted and cache favorites for its hand-over

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: make home's first live frame match its boot snapshot

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: save the home snapshot with its boot stylesheets and through keyboard reloads

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 03:53:05 +01:00

409 lines
14 KiB
HTML

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="/logo.svg" />
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
<meta name="theme-color" media="(prefers-color-scheme: light)" content="#fbfbfd" />
<meta name="theme-color" media="(prefers-color-scheme: dark)" content="#3b4252" />
<meta name="mobile-web-app-capable" content="yes" />
<style type="text/css" data-wm-shell>
html[data-wm-home-snapshot] #svelte-global-loader {
display: none;
}
#wm-home-snapshot * {
animation: none !important;
transition: none !important;
}
.st2 {
fill: #bcd4fc;
}
.st3 {
fill: #3b82f6;
}
/* Public app pages render their shell before app.css loads, if at all. */
html[data-wm-public-app] #svelte-global-loader {
display: none;
}
html[data-wm-public-app] body {
margin: 0;
}
html[data-wm-public-app='dark'] body {
background-color: #3b4252;
}
/* Background color for dark mode */
@media (prefers-color-scheme: dark) {
#mainbg {
background-color: #3b4252; /* Example: dark gray background for dark mode */
}
#loading-text {
color: #a8aeb7 !important;
}
}
</style>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script>
// WIN-2006: when the app is rendered inside an opaque-origin (sandboxed,
// no allow-same-origin) iframe, Web Storage access throws a SecurityError.
// Install an in-memory shim before the SvelteKit app boots so the app (and
// Windmill SPA code running inside the frame) keeps working within the
// session. No-op in normal real-origin contexts, so zero blast radius.
;(function () {
// `onOp` (localStorage only) relays each mutation up to the embedder,
// which backs a single store shared across all apps. sessionStorage
// stays in-memory/session-only.
function shim(onOp) {
var m = {}
return {
__hydrate: function (obj) {
if (obj) for (var k in obj) m['' + k] = '' + obj[k]
},
getItem: function (k) {
k = '' + k
return Object.prototype.hasOwnProperty.call(m, k) ? m[k] : null
},
setItem: function (k, v) {
m['' + k] = '' + v
if (onOp) onOp({ op: 'set', key: '' + k, value: '' + v })
},
removeItem: function (k) {
delete m['' + k]
if (onOp) onOp({ op: 'remove', key: '' + k })
},
clear: function () {
for (var k in m) delete m[k]
if (onOp) onOp({ op: 'clear' })
},
key: function (i) {
var ks = Object.keys(m)
return i < ks.length ? ks[i] : null
},
get length() {
return Object.keys(m).length
}
}
}
try {
window.localStorage.getItem('__wm_probe__')
} catch (e) {
var framed = window.parent !== window
function relayOp(o) {
if (framed)
try {
window.parent.postMessage(
{ type: 'wm_ls_op', op: o.op, key: o.key, value: o.value },
'*'
)
} catch (_) {}
}
var ls = shim(framed ? relayOp : null)
try {
Object.defineProperty(window, 'localStorage', { value: ls, configurable: true })
} catch (_) {}
try {
Object.defineProperty(window, 'sessionStorage', {
value: shim(null),
configurable: true
})
} catch (_) {}
// Persistence: ask the embedder for the shared store and hydrate the
// in-memory localStorage when it arrives.
if (framed) {
window.addEventListener('message', function (ev) {
if (ev.source === window.parent && ev.data && ev.data.type === 'wm_ls_hydrate') {
ls.__hydrate(ev.data.data)
}
})
try {
window.parent.postMessage({ type: 'wm_ls_req' }, '*')
} catch (_) {}
}
// `document.cookie` also throws in an opaque origin; back it with an
// in-memory jar so reads don't crash apps. This is NOT the real
// session cookie (unreachable here) — just an isolated client-side store.
try {
var jar = {}
Object.defineProperty(Document.prototype, 'cookie', {
configurable: true,
get: function () {
return Object.keys(jar)
.map(function (k) {
return k + '=' + jar[k]
})
.join('; ')
},
set: function (v) {
var p = String(v).split(';')[0]
var i = p.indexOf('=')
if (i > -1) jar[p.slice(0, i).trim()] = p.slice(i + 1).trim()
}
})
} catch (_) {}
}
})()
</script>
<script>
// Public app pages (`/public/<ws>/<secret>`, `/a/<custom path>`): skip the loading
// screen, and start the API calls the page makes first so they overlap the module
// download instead of following it. `publicAppApi.ts` takes these responses by URL,
// so each URL here must be exactly what it requests. Only the cookie credential is
// prefetched: a share link carrying a JWT, or the opaque viewer frame (`wm_embed`),
// sends its own and fetches normally. The bundle of an unsandboxed raw app is
// requested as soon as its secret is known, for the iframe to find in the HTTP cache.
;(function () {
var path = location.pathname
var pub = /^\/public\/([^/]+)\/([^/]+)\/?$/.exec(path)
var custom = /^\/a\/(.+?)\/?$/.exec(path)
if (!pub && !custom && !/^\/public\//.test(path)) return
// Dark as PublicApp decides it, painted before any stylesheet so that a dark app
// does not load over a white page.
var dark = false
try {
var mode = localStorage.getItem('dark-mode')
dark = mode ? mode === 'dark' : matchMedia('(prefers-color-scheme: dark)').matches
} catch (_) {}
document.documentElement.setAttribute('data-wm-public-app', dark ? 'dark' : '')
if (new URLSearchParams(location.search).get('wm_embed') === '1') return
var prefetched = (window.__wmPublicAppPrefetch = {})
function get(url) {
var res = fetch(url)
res.catch(function () {})
prefetched[url] = res
return res
}
function warmBundle(appRes, workspace) {
appRes
.then(function (r) {
return r.ok ? r.clone().json() : null
})
.then(function (app) {
if (!app || !app.raw_app || !app.bundle_secret || (app.policy || {}).sandbox) return
var ws = workspace || app.workspace_id
var v = '/api/w/' + ws + '/apps_u/get_data/v/' + app.bundle_secret
fetch(v + '.css').catch(function () {})
fetch(v + '.js').catch(function () {})
})
.catch(function () {})
}
if (pub) {
var w = '/api/w/' + pub[1]
get(w + '/apps_u/embed_token/' + pub[2])
warmBundle(get(w + '/apps_u/public_app/' + pub[2]), pub[1])
get(w + '/apps_u/guest_entry/' + pub[2])
get(w + '/users/whoami')
} else if (custom && custom[1].indexOf('.') === -1) {
// A `.` marks a trailing JWT segment, which no custom path contains.
get('/api/apps_u/embed_token_by_custom_path/' + custom[1])
warmBundle(get('/api/apps_u/public_app_by_custom_path/' + custom[1]))
get('/api/apps_u/guest_entry_by_custom_path/' + custom[1])
}
get('/api/ee_license')
})()
</script>
%sveltekit.head%
<script id="wm-home-snapshot-head">
// A reload of Home paints the last rendered Home (homeSnapshot.ts) in place of the splash
// while the app boots. Bound like the optimistic render (lastSession.ts): only under the
// session hint it was saved with, else it is dropped, so the next person on a shared
// browser never sees it; only for the workspace this load opens, at the width and theme
// it was rendered at. Its stylesheets are content-hashed files of the build it was saved
// by, hence the build check; they are written by the parser so they block the first
// paint as the build's own would, and one failing to load drops the snapshot.
;(function () {
var KEY = 'wm-home-snapshot'
var s
function drop() {
window.__wmHomeSnapshot = undefined
document.documentElement.removeAttribute('data-wm-home-snapshot')
var shot = document.getElementById('wm-home-snapshot')
if (shot) shot.remove()
try {
localStorage.removeItem(KEY)
} catch (_) {}
}
// Every other page, the public apps included, pays nothing for it.
if (location.pathname !== '/' || window.parent !== window) return
try {
var raw = localStorage.getItem(KEY)
if (!raw) return
s = JSON.parse(raw)
var hint
document.cookie.split(/;\s*/).forEach(function (c) {
var eq = c.indexOf('=')
if (eq > 0 && c.slice(0, eq) === s.cookie) hint = c.slice(eq + 1)
})
var age = Date.now() - s.savedAt
if (
s.format !== 1 ||
s.build !== '%sveltekit.version%' ||
!hint ||
hint !== s.hint ||
!(age >= 0 && age < 7 * 24 * 3600 * 1000)
)
return drop()
var params = new URLSearchParams(location.search)
var other = false
params.forEach(function (_, k) {
if (k !== 'workspace') other = true
})
// The workspace the app opens, as stores.ts and the (logged) layout pick it.
var ws = params.get('workspace')
if (ws === null) ws = sessionStorage.getItem('workspace')
if (ws === null) ws = localStorage.getItem('workspace')
var mode = localStorage.getItem('dark-mode')
var dark =
mode !== null ? mode === 'dark' : matchMedia('(prefers-color-scheme: dark)').matches
if (other || ws !== s.workspace || innerWidth !== s.width || dark !== s.dark) return
} catch (_) {
return
}
var html = document.documentElement
html.setAttribute('data-wm-home-snapshot', '')
;['dark', 'github-dark'].forEach(function (c) {
html.classList.toggle(c, (' ' + s.htmlClass + ' ').indexOf(' ' + c + ' ') !== -1)
})
document.addEventListener(
'error',
function (e) {
var t = e.target
if (t && t.tagName === 'LINK' && t.hasAttribute('data-wm-home-snapshot')) drop()
},
true
)
var links = ''
s.stylesheets.forEach(function (href) {
links +=
'<link rel="stylesheet" data-wm-home-snapshot href="' +
String(href).replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/</g, '&lt;') +
'">'
})
document.write(links)
s.styles.forEach(function (css) {
var style = document.createElement('style')
style.setAttribute('data-wm-home-snapshot', '')
style.textContent = css
document.head.appendChild(style)
})
window.__wmHomeSnapshot = s
})()
</script>
</head>
<body data-sveltekit-preload-code="viewport" class="outline-none focus:outline-none">
<div id="wm-app" style="display: contents">
<div id="svelte-global-loader">
<div id="mainbg" style="position: absolute; bottom: 0; left: 0; width: 100%; height: 100vh">
</div>
<div style="position: fixed; left: 50%; top: 40%; transform: translate(-50%, -50%)">
<svg
version="1.1"
id="Windmill"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
x="0px"
y="0px"
width="128px"
height="128px"
viewBox="0 0 256 256"
style="enable-background: new 0 0 256 256"
xml:space="preserve"
>
<g>
<polygon
class="st2"
points="134.78,14.22 114.31,48.21 101.33,69.75 158.22,69.75 177.97,36.95 191.67,14.22 "
/>
<polygon
class="st3"
points="227.55,69.75 186.61,69.75 101.33,69.75 129.78,119.02 158.16,119.02 228.61,119.02 256,119.02 "
/>
<polygon
class="st3"
points="136.93,132.47 116.46,167.93 73.82,241.78 130.71,241.78 144.9,217.2 180.13,156.18 193.82,132.46
"
/>
<polygon
class="st3"
points="121.7,131.95 101.23,96.49 58.59,22.63 30.15,71.91 44.34,96.49 79.57,157.5 93.26,181.22 "
/>
<polygon
class="st2"
points="64.81,131.95 25.15,131.21 0,130.74 28.44,180.01 66.73,180.72 93.26,181.21 "
/>
<polygon
class="st2"
points="165.38,181.74 184.58,216.46 196.75,238.47 225.19,189.2 206.66,155.69 193.83,132.46 "
/>
</g>
</svg>
<div
id="loading-text"
style="
text-align: center;
margin-top: 30px;
color: gray;
font-family: Arial, Helvetica, sans-serif;
"
>
Loading...
</div>
</div>
</div>
<script id="wm-home-snapshot-body">
// The snapshot the head script accepted. Not interactive: its content is inert, and the
// cover above it takes the pointer until the live Home replaces it (homeSnapshot.ts).
// A boot that never gets there gives the splash back.
;(function () {
var s = window.__wmHomeSnapshot
if (!s) return
try {
var shot = document.createElement('div')
shot.id = 'wm-home-snapshot'
shot.setAttribute('aria-hidden', 'true')
shot.style.cssText =
'position:fixed;inset:0;z-index:2147483647;overflow:hidden;cursor:progress'
shot.style.background = s.background
var parsed = new DOMParser().parseFromString(s.html, 'application/xhtml+xml')
if (parsed.getElementsByTagName('parsererror').length) {
document.documentElement.removeAttribute('data-wm-home-snapshot')
try {
localStorage.removeItem('wm-home-snapshot')
} catch (_) {}
return
}
// Cleaned again here, not only when saved: anything that can write this origin's
// storage once could otherwise plant markup that runs on every load of Home.
var executable =
/^(script|iframe|frame|object|embed|link|meta|base|form|animate|set|animatemotion|animatetransform)$/i
Array.prototype.forEach.call(parsed.querySelectorAll('*'), function (el) {
if (executable.test(el.localName)) return el.remove()
Array.prototype.slice.call(el.attributes).forEach(function (a) {
var v = a.value.replace(/[\u0000-\u0020]/g, '')
if (/^on/i.test(a.name) || /^(javascript|vbscript):/i.test(v))
el.removeAttribute(a.name)
})
})
var content = document.importNode(parsed.documentElement, true)
content.setAttribute('inert', '')
content.style.height = '100%'
shot.appendChild(content)
var loader = document.getElementById('svelte-global-loader')
loader.parentNode.insertBefore(shot, loader.nextSibling)
setTimeout(function () {
shot.remove()
document.documentElement.removeAttribute('data-wm-home-snapshot')
}, 15000)
} catch (_) {
document.documentElement.removeAttribute('data-wm-home-snapshot')
}
})()
</script>
%sveltekit.body%
</div>
</body>
</html>