Page:
Swap Lifecycle
Pages
AI Use Disclosure
Adding Things
Architecture
Author
Background Worker
Code Layout
Command Line Modes
Common Pieces
Components and Contracts
Configuration
Database
Dev Login
Discord
Features
Frontend Layout
Frontend
Home
Installation
Logging
Look and Feel
Notifications
Performance Principles
Roadmap
Running
SSO Flow
Security
Static Data
Swap Lifecycle
Swarm Cache
Token Refresh and Caching
Updating
No results
2
Swap Lifecycle
Nate edited this page 2026-11-21 20:21:39 -08:00
Table of contents
The swap lifecycle (the part that bites)
Navigation does not reload the page. swap.js fires, in order:
evesynapse:content-will-swapon document: teardown time.#main-contentis replaced.evesynapse:content-readyon document, withdetail.rootset to the new fragment.
Rules that follow from this:
- Widgets subscribe, they don't run at parse time. Use
EveSynapseContent.onReady(fn);fn(root)runs once for the first paint and again for every swap, with the fresh fragment asroot. Initialize only what's insideroot. - Initializers must be idempotent and root-scoped. Running
twice over the same markup must be harmless; query inside
root, never the whole document, for widget elements. - Element bindings are safe; global ones are on you. Listeners
on elements inside the fragment die with it. Anything bound to
document/window, and every timer, must be guarded against double-binding or torn down oncontent-will-swap(the countdown ticker and the page-sync loop are the worked examples in app.js). - Shell code binds once and never re-runs: if it needs to react to new content (the modal closer, the character-selector pruner), it listens for the lifecycle events itself.
- A dialog open inside content being swapped out closes with it.
- The swapper never strands a page without its assets. A swap adopts the incoming page's stylesheet and any page scripts the shell hasn't loaded (in document order, against the swapped-in content, before content-ready), and prunes the stylesheet again when a later page doesn't carry it. Only an asset that fails to load falls back to a full navigation: plus the pages whose JS holds state (the fitting simulator and saved fits always load whole regardless). That's what makes per-surface files safe: gate the file in base.html and the swap brings it along.