13. Client features register themselves
13. Client features register themselves (#322, part 1 of #317)
Section titled “13. Client features register themselves (#322, part 1 of #317)”- [E] Decided by the owner (2026-11-19, #317):
src/client/main.tsstops growing; a client feature registers itself like a round setting (#310). No change of the game, of a text or of the behaviour. - [V] Built with #322 (main agent’s proposal, the owner decided only that
the pattern comes): a feature has one module
src/client/features/<name>.tsthat exports under the fixed nameclientFeature,export const clientFeature = { acts: (ctx) => ({ ... }) } satisfies ClientFeature;.actsreturns thedata-acthandlers of the feature: a name from the markup (data-act="build") to a function that gets thedata-*attributes of the element.ClientFeatureand the contextClientCtxare insrc/client/features/contract.ts. - [V]
ClientCtxholds only what moved code really needs frommain.ts:actandactHere(send an action;actHereis true only on the place still shown, #209),modal,go,render,api,toastandsetInput. The state is not in it: a module importsclientfromlogic/state.svelte.ts, which also holdsclient.ui.main.tsbuilds one object and hands it to every module. A member is added when a module needs it, not before. - [V] Two more members of
ClientFeatureexist, both optional, each added with the first module that needed it:forms, the submit handlers by the id of the form (the submit is stopped, then the handler runs; a form that clears itself with its own listener, asabandon,marketandsocialdo, needs none), andafterRender, which runs after each render at the place wheremain.tscalled the fleet preview before. A module may also listen to the document itself when itsactsis built (change, input, keydown, submit);main.tsbuilds the table once, at start. - [V] The list of the modules is generated:
scripts/gen-features.tswritessrc/client/features/index.gen.ts(CLIENT_FEATURES,[name, clientFeature]pairs sorted by file name), not checked in (.gitignore), from every file of the folder that exportsclientFeature(same detection and write-if-changed as forroundSettings; not a test, not a generated file). Knip takes it as an entry; Vitest coverage, Stryker and the dependency rules need no entry, as they do not look atsrc/client/featuresor at generated files.main.tsimports only this list and names no feature: it builds its tables from its own frame handlers (login, the planet choice, the admin panel, navigation, the click and key dispatch) and the handlers of all modules throughassembleActsandassembleForms(src/client/features/assemble.ts), and callsrunAfterRender. - [V] The rules for all modules are checked in two places. The functions
of
assemble.tsthrow when a handler name or a form id is defined twice, between two modules or between a module and a frame handler, so there is no silent overwrite by spread order and the page fails at start, not in one click.src/client/features/registry.test.tschecks every listed module (exportsclientFeaturewithacts, plain names, no name twice) and the functions themselves; the frame handlers ofmain.tsare checked only at start, asmain.tscannot be imported in a test. Each module tests its own handlers with a fakectx(test-ctx.ts): what a handler sends throughctx.actand what it shows, without DOM snapshots. - [E] A clicked
data-actelement is locked while the promise of its handler runs and unlocked infinally, whatever the outcome; a second click on it does nothing (owner, 2026-11-26, 186a, #425). A handler that returns no promise locks nothing. [V] The lock is per element, held in aWeakSetbyrunLockedofsrc/client/logic/act-lock.tsand called bysrc/client/dispatch.ts: it blocks no other button, sets nodisabledoraria-busy(so adisabledthe view sets is never removed), and a node that a render puts in place of the locked one is free at once. - [E] Every form, the chats included, is locked the same way while the
promise of its handler runs: two quick Enter or a double click on its
submit button send it once, and it is free again at once when the action
ended, also after a refusal or a network error (owner, 2026-11-27, 284a,
#428; before, forms were not locked, 186a). A handler without a promise
locks nothing. [V] Every place that sends a form goes through
runLockedofsrc/client/logic/act-lock.ts, keyed by the form:- the forms of the features’
formsmaps:submitLocked, the submit listener ofsrc/client/dispatch.ts(a form without a handler keeps its default); - the forms with a submit listener of their own:
guildchatformandfriendform(features/social.ts),abandonform(features/abandon.ts),marketform(features/market.ts); - the
onsubmitof the forms of the views, throughlockedSubmit(it always stops the default): the private messages (PmCompose,PmSettings), the deletion of the account (DeleteAccountDialog), and the admin’s forms (AdminDiagnostics: filter and moderation,AdminErrors: download,AdminTable: „Mond anlegen“). The second form ofAdminErrors, the filter, sends nothing and only stops its default. The server recognising repeated actions itself is #450 (292a).
- the forms of the features’
- [V] Small reads of the page that
main.tsand the modules share are insrc/client/dom.ts($,val,byId,setById,keepChatScroll). - [V] Built:
abandon,round,market,social,options,fleet(with the fleet form and its preview),missiles,lexicanumanddemolition(which delegates tologic/demolition.ts) were handlers outsidemain.tsbefore and are modules now, and the collecting filefeature-actions.tsis gone; then moved out ofmain.ts:guilds,galaxy,reports,passkeys,report-problem,admin(the Endzeit, the settings and copying the link),queue,rename,highscore,achievements,pushandinstall. What stays inmain.tsis the frame: start, the API call, the state, the rendering, the login and its forms, the news and the maintenance banner, the admin panel and the click and key dispatch. Each move lowers the line count ofmain.ts, which is the limit of the next change (size-ratchet.jsonis gone, #317 part 4).
Package 8 of #118: what is left of main.ts (owner, 2026-11-19)
Section titled “Package 8 of #118: what is left of main.ts (owner, 2026-11-19)”- [E] Decided by the owner (#118, Nachtrag 4, 2026-11-16, and the
comment of 2026-11-19):
main.tsis only the entry point, and the parts that are not views have modules of their own; behaviour that lived only inmain.tssurvives. - [V] Built: the transport is
logic/transport.ts(createApi, with its tests: 401, maintenance, the retry of a busy action, errors) wired to the page inapi.ts; the session (session.ts), the banner of a maintenance (maintenance.ts), the toasts with „Problem melden“ (toast.ts) and the error log (error-log.ts) are modules of their own. The state and the render aresync.ts(apply, act, refresh),render.ts,completions.ts,news.ts,routing.ts,view-address.ts,dispatch.ts(the click and submit dispatch with the context of the features),clock.ts,boot.tsandui-init.ts. The frame handlers (sheet „Mehr“, dialog, planet choice, logout), the share of a producer, the animations, the activity sample and the marks „gelesen“ are the featuresframe,producers,options,session-activityandreading; a feature that only listens to the page returns no handlers.ClientCtxgotquietandapply(state, fresh). - [V] Forms own their input: „Account löschen“ is a component
(
views/DeleteAccountDialog.svelte) with its own password and busy state; the message of the guild chat and the name of a new buddy show a draft oflogic/drafts.svelte.ts. - [E] Owner, 2026-11-20 („all now“):
keepInputsis gone and so is everydata-nokeep. The uniform field drafts that shipped with the update (logic/field-drafts.ts,field-drafts.ts,restoreFieldsinrender.ts) are deleted again (#332, 2026-11-21): every form that the poll redraws keeps its fields as the state of its component (section „Per-form component state“), and nothing restores a field after a redraw. A fresh render (another view or planet) and a logout drop that state, as they dropped the typed fields before. Fields without state show the state of the server: the settings of the universe (logic/settings-draft.tskeeps their draft), the link of the invitation and the confirmation of a dissolving (a modal outside#view); chat and buddy name have their own drafts (logic/drafts.svelte.ts). The amounts of the four lists (q_<key>,td_<key>) keep their value in the page: the lists are redrawn in place (renderMounted, they are notanew) and the two fields carry no value, binding or handler of the component, so the poll never writes or replaces them (src/client/views/list-fields.test.ts, E2Ee2e/redraw-drafts.spec.ts). - [E] Owner, 2026-11-20, made stricter by #332: no client code sets the
value, tick or chosen option of a field, except
setFieldofsrc/client/dom.ts, whichsetInputandsetByIduse for the fields that hold their value in the page (the amounts of the lists, the settings of the universe). A field of a form with state is shown by its component and written through that state. The guardsrc/test/field-writes.test.tsreads the syntax trees ofsrc/client(TypeScript and Svelte, tests excluded) and fails on.value =,.checked =,.selectedIndex =,.selected =(also+=,++,["value"] =) andsetAttribute('value', …)anywhere but insidesetField; it has no allow-list of files. A Sveltebind:orvalue={…}is no write.normalize()ofsrc/test/markup.tsignoresdata-nokeep, so the frozen HTML of the reference tests stays as it was. E2E:e2e/redraw-drafts.spec.ts. - [E] Owner, 2026-11-20:
acts()andforms()are free of side effects. A feature registers its page listeners (change, input, keydown, submit, window events) in the optional hooklisten(ctx), which the assembly calls once at start (startListenersinassemble.ts, called bydispatch.ts).registry.test.tschecks that every feature contributes something (acts, forms,afterRenderorlisten) and that buildingactsandformsadds no listener to the document or the window.
Per-form component state (#332)
Section titled “Per-form component state (#332)”-
[E] Owner, 2026-11-20 (#118, package 8, and #332): each form that the poll redraws keeps its fields as state of its component, so a redraw cannot lose them and no restore step is needed; when no form depends on the field drafts,
field-drafts.ts,logic/field-drafts.ts,restoreFieldsand the allow-list entry of the guard are deleted. No visible change. Done on 2026-11-21: the last fields (the fleet form, part two) were converted, the drafts are deleted, and the guard has no allow-list. -
[V] The state of a form is a module of its own, as a view that is mounted anew loses what its component held:
formState()oflogic/form-state.svelte.ts(dropped by a fresh render and a logout,forgetFormsinrender.ts), or a$stateof the form’s own module where the form never dropped its draft (the marketplace,logic/market-form.svelte.ts). The component binds it and the handler reads and writes it. Built: the filter of the achievements (logic/achievement-filter.svelte.ts), the position of the Sternenkarte (logic/galaxy-position.svelte.ts), the marketplace, and the ships, position, speed, cargo and names to invite of the fleet form (logic/fleet-form.svelte.ts, read byreadFleetForm, written by the handlers offeatures/fleet.tsandfeatures/union.ts; a field of the position that nobody typed in shows the target of the page,fleetTargetoflogic/fleet-choice.ts). Part two of the fleet form: the kind of target, the mission, the union, the holding time and the stay, and the „Zielmond“ of the Warp-Tor are state of the same module as well, and what the lists and the row of the time show for that state is worked out by one pure function,fleetChoice()oflogic/fleet-choice.ts, whichFleet.svelteasks (the page gives it asform.choose) and the handlers read (readFleetForm): the list „Auftrag“ (missionChoicesoflogic/fleet-target.ts), the note of the limit of planets, the state of „Flotte losschicken“, the row „Haltezeit“ (stay with its real time, or the holding time, hidden for a mission that does not hold), the moon option and the union all come from it, with no HTML string and no write into the DOM after a render. A field nobody touched shows the page (ui.ft,ui.fm,ui.fk,ui.union, which also carry the choice over to the next form of a fresh render);fleetCalcsettles the state on every input (a moon that is not there goes back to the planet, the mission the list ended on is kept, the row of the other time starts again with 1 hour). The „Schnellwahl“ has no state: it enters the target into the state and goes back to „– wählen –“. The list of missions follows the kind as asked andfleetCalcsettles a moon that is not there before it reads the mission, so the first frame of a form that aims at a moon that is not there equals the frozen reference markup (src/test/fleet-reference.test.ts, unchanged). A handler that dispatches an input event after it wrote the state callsflushSync()first, else the component’soninputwould read the old value back from the field. „Optionen“ (logic/options-form.svelte.ts): the choices, the passwords and the text of „Problem melden“; a select shows the option chosen, else the one of the page (isChosen). The handlers still read the fields by id (the login sharespw_nextandpw_confirm), which show the state; „Passkey hinzufügen“ and a sent report empty the state, so a redraw no longer puts the sent text back afterform.reset(). „Gilden“ (logic/guild-form.svelte.ts): the profile, the names of the ranks, the name of a new rank, the rank chosen for a member and the ticks of the rights; a disabled box shows the server (ticked, #163), and „Rang anlegen“ empties the name.isChosen(form-state.svelte.ts) is the option a select shows. With the rank boxes gone from the drafts, the drafts keep values only (no ticks). „Admin“ (logic/admin-form.svelte.ts): the address to invite and the message to all players, which a sent message empties; the filters keep theirs inlogic/admin-panels.svelte.ts. -
[V] A number field whose state is a string takes
value={…}withoninput, notbind:value. Checked againstbind_valueof Svelte 5.57 (2026-11-21, with a fake input):bind:valuestores the field as a number ornull, and with a getter that has a fallback (the Sternenkarte shows the shown system while nothing is typed) it writes the fallback over a half-typed value (a browser reports-or1eas an empty value).value={…}writes the field only when the state differs from what the field holds (set_value), so a half-typed value stays. A select may usebind:value. -
[V] Taken by the coordinator under the rule of AGENTS.md, consistent with the owner’s decision that each form keeps its state in its component (2026-11-21; the owner can overturn them):
- the fix of „Problem melden“ (a sent text no longer comes back after the
poll redraw) stays, with a changelog fragment, because the issue lists
the
form.reset()case as a defect; - the fleet form, part two: the mission list, the row of holding time and
stay and the moon option are derived in
Fleet.sveltefrom the state of the component; the frozen reference test is the judge (done, the reference test is unchanged); - the amounts of the four lists (
q_*,td_*) do not depend on the drafts (a poll redraw does not mount them anew; a test shows it), so the drafts are deleted after the fleet form, part two; if the test shows otherwise for a field, the deletion stops (the test shows it, the drafts are deleted).
- the fix of „Problem melden“ (a sent text no longer comes back after the
poll redraw) stays, with a changelog fragment, because the issue lists
the
Inventory: where each field keeps its value (2026-11-21, after the last conversion)
Section titled “Inventory: where each field keeps its value (2026-11-21, after the last conversion)”No field depends on the drafts any more. A field with an id inside #view
keeps its value in one of these places:
- Flotte (
Fleet.svelte, mounted anew): all fields are state oflogic/fleet-form.svelte.ts, dropped by a fresh render:f_<ship>,t_g,t_s,t_p,t_v,c_m,c_c,c_d,un_name_<union>(converted earlier today) andt_k,t_m,t_u,t_h,t_stayandjg_to(part two);t_q„Schnellwahl“ has no state to keep (see above). The handlers read what the form shows throughfleetChoice(), not from the fields, as a read of the field right after a state change would see the old value (the component updates the DOM after the handler). - Optionen (
Options.svelte):logic/options-form.svelte.tsforo_probes,o_explain,o_levels,o_main,pw_current,pw_next,pw_confirm,passkey-passwordandreportform-text.o_animand the push boxes are checkboxes whose state is the setting applied at once byfeatures/options.ts. - Gilden:
logic/guild-form.svelte.tsforguild_tag,guild_name,guild_description,rank_name_<rank>,rank_<rank>_<right>,rank_newandrank_of_<member>.chat_texthas its own draft (logic/drafts.svelte.ts). - Admin:
logic/admin-form.svelte.tsforinv_emailandannounce-text;audit-playerandaudit-outcomeand the other filters keep theirs inlogic/admin-panels.svelte.ts.set_*(logic/settings-draft.ts) andinv_linkshow the server. - Marktplatz, the filter of the achievements and the position of the
Sternenkarte: their own state modules (
logic/market-form.svelte.ts,logic/achievement-filter.svelte.ts,logic/galaxy-position.svelte.ts). - Gebäude, Forschung, Schiffsschmiede, Verteidigung (
CatalogList.svelte):q_<key>(written byfeatures/queue.ts) andtd_<key>(emptied byfeatures/missiles.ts) hold their value in the page, throughsetField; they are redrawn in place and never written by a render (views/list-fields.test.ts).
Fields with nothing to convert: „Freunde“ (friend_name has its own
draft); the search of the Lexicanum (no id, its state is
views/lexicanum-state.svelte.ts); the login (Auth.svelte: no signed-in
player, nothing to redraw); the list „Aktiver Planet“ (planet_select, in the
header); every dialog of #modal („Neue Runde“ RoundDialog,
EndzeitDialog, „Übergeben“ and „Auflösen“ GuildDialogs, „Account
löschen“, „Problem melden“, the missiles, renaming, abandoning): outside
#view. The redraw is checked by e2e/redraw-drafts.spec.ts (fleet,
marketplace, new guild, Sternenkarte, achievements, both filters of the admin,
the amounts of the lists).
The actions are typed (#317, #118; owner, 2026-11-20)
Section titled “The actions are typed (#317, #118; owner, 2026-11-20)”-
[E] Decided by the owner (2026-11-20, „jetzt komplett“): the call of an action is checked by the compiler against the input the server declares (
okf/architecture/patterns/14-server-features.md, the map insrc/core/actions/). -
[V]
act,actHereandquietofClientCtx(andSync.sendandSync.quietoflogic/act.ts) are<K extends ActionName>(type: K, ...data: ActionArgs<K>): the name picks the type of the data, and the data may be left out only where every field of the input is optional. A name or a field that does not exist is a compile error at the call. The reads of the archive (features/round-archive.ts), which went throughctx.apiby hand, use the same types.data-actnames of the markup are the names of the handlers of the features, not action names, and stay strings. The handlers of the buddy list return a typed call (FriendCall), sent bysendFriendoffeatures/social.ts, as a union of tuples cannot be spread into a generic call. -
[V] The state is typed the same way:
GameStateoflogic/types.tsis derived from the shapes of the parts insrc/core/state/and no longer written by hand;logic/types.tsre-exports the names the views use. -
[E] Changed for #542, not built yet (owner, 2026-11-30): every feature gets one folder
src/features/<feature>/with its rules and checks, its action inputs and state shape, its Lexicanum page, its server part (*.server.ts) and its client part (*.client.ts), and its tests;src/corekeeps only what two or more features share. This replaces, once #542 is built, the place of the checks insrc/core(pattern 7), the ban of client code in a feature folder (pattern 11) and the separate places of pattern 13 and 14. Names are readable (#543), and each rule exists once and is checked by the server (#544).