@jsenv/navi 0.29.226 → 0.29.227

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -116,7 +116,8 @@ to start when unsure which export solves a problem.
116
116
  writes politely. Read before caching responses in the app.
117
117
  - `dynamic_import.md` — a screen's code arrives like its data: a page's
118
118
  import is a `routeAction` read with `loading: true` (a branch, not a
119
- `<Loading>`), a component reads its own with `useAsyncData(() => import(…))`;
119
+ `<Loading>`), a component's is started by what asks — `actionRunEffect` on a
120
+ state, `useAsyncData(() => import(…))` only as the fallback;
120
121
  links prerun on intent what asks nothing of the address; a transition
121
122
  photographs the pending screen; a chunk's `import.meta.css`; a chunk that
122
123
  does not come is never a bug and never comes twice in one document — offer
@@ -7,8 +7,10 @@ the network is gone or a deploy happened in between — and nothing on screen
7
7
  should have to know whether what it waits for is bytes of data or bytes of
8
8
  code.
9
9
 
10
- So navi has nothing lazy-shaped: **the import is an action**, read by the hook
11
- a screen already reads its data with. Two shapes, decided by who asks.
10
+ So navi has nothing lazy-shaped: **the import is an action**, started by what
11
+ asks for it — the address through `routeAction`, a state through
12
+ `actionRunEffect` — and read by the hook a screen already reads its data
13
+ with. Running it from the hook itself is the fallback, as for data.
12
14
 
13
15
  ## A page: its code is a route action
14
16
 
@@ -72,43 +74,66 @@ The page module itself is ordinary — it reads its data with
72
74
  `useAsyncData(GAME_PAGE_ACTION)` like any page — and imports the routes module
73
75
  back for it; a dynamic import is not a load-order cycle.
74
76
 
75
- ## A component inside a page that stays: it reads its own code
77
+ ## A component inside a page that stays: who asks for its code
76
78
 
77
79
  A plan drawn on demand inside a page that stays knows where it is drawn and
78
- what stands there — a frame, a line, a button. `useAsyncData` takes a
79
- function: the request this component owns, made into an action once on the
80
- first render and kept for the life of the instance, its answer as the data.
81
- The wait and the failure are then drawn where the frame is, and no boundary is
82
- involved:
83
-
84
- ```jsx
85
- const PlanSection = () => {
86
- const [Plan, loading, error] = useAsyncData(
87
- () => import("./plan.jsx").then((m) => m.Plan),
88
- { loading: true, error: true },
89
- );
90
- return (
91
- <PlanFrame>
92
- {loading ? <Text>…</Text> : null}
93
- {error ? <Button action={() => reload()}>Recharger</Button> : null}
94
- {Plan ? <Plan /> : null}
95
- </PlanFrame>
96
- );
97
- };
98
- ```
99
-
100
- The same reasons as for a page hold: nothing stands there yet, so a
101
- suspension would only swap and remount for nothing. Delegating instead
102
- (`useAsyncData(fn)` alone, under a `<Loading>` around the frame) follows the
103
- rule for data: **the `<Loading>` goes where the fallback should land.** A
104
- boundary around the whole router takes the router away while a page loads —
105
- top bar, tabs and all.
106
-
107
- This shape starts at the render and is per instance: a component fetched this
108
- way in three places asks three times (the browser fetches the module once),
109
- and coming back to it suspends for the microtask the import takes to answer
110
- from the module map. A page wants the route action shape; a section inside a
111
- page rarely notices.
80
+ what stands there — a frame, a line, a button. The wait and the failure are
81
+ drawn where the frame is, with `loading: true` and `error: true`, the same way
82
+ as for a page. What differs is **who starts the import**, and the order of
83
+ preference is the one `useAsyncData` states for data: **the run belongs to
84
+ what asks, not to the render.**
85
+
86
+ 1. **The address asks** → `routeAction`, above. A section of a page that has
87
+ an address (`/places/:id/plan`) is a page.
88
+ 2. **A state asks** → `actionRunEffect`. A plan drawn once a mode is entered,
89
+ a tab chosen, a popup opened: the signal that says so is what starts the
90
+ import, declared once at module scope — one action for every instance,
91
+ started by the state change rather than by the render that follows it,
92
+ and holding its answer across mounts:
93
+
94
+ ```jsx
95
+ const PLAN_CODE = actionRunEffect(
96
+ () => import("./plan.jsx").then((m) => m.Plan),
97
+ () => planShownSignal.value,
98
+ );
99
+
100
+ const PlanSection = () => {
101
+ const [Plan, loading, error] = useAsyncData(PLAN_CODE, {
102
+ loading: true,
103
+ error: true,
104
+ });
105
+ return (
106
+ <PlanFrame>
107
+ {loading ? <Text>…</Text> : null}
108
+ {error ? <Button action={() => reload()}>Recharger</Button> : null}
109
+ {Plan ? <Plan /> : null}
110
+ </PlanFrame>
111
+ );
112
+ };
113
+ ```
114
+
115
+ 3. **Nothing above the component asks** → `useAsyncData` with a function, the
116
+ fallback: the component's own existence is the only thing that asks, so the
117
+ request is its own, made into an action once on the first render and kept
118
+ for the life of the instance.
119
+
120
+ ```jsx
121
+ const [Plan, loading, error] = useAsyncData(
122
+ () => import("./plan.jsx").then((m) => m.Plan),
123
+ { loading: true, error: true },
124
+ );
125
+ ```
126
+
127
+ It starts one render late, and per instance: a component fetched this way
128
+ in three places asks three times (the browser fetches the module once), and
129
+ coming back to it suspends for the microtask the import takes to answer
130
+ from the module map. Reach for it when there is genuinely no state to read
131
+ the request off — not to save declaring one.
132
+
133
+ Delegating instead (the hook without `loading: true`, under a `<Loading>`
134
+ around the frame) follows the rule for data: **the `<Loading>` goes where the
135
+ fallback should land.** A boundary around the whole router takes the router
136
+ away while a page loads — top bar, tabs and all.
112
137
 
113
138
  Nothing has to be kept out of a subtree loaded this way: the suspension
114
139
  happens before the module's components exist, so nothing inside it is parked
@@ -325,6 +325,13 @@ being sent: everything — the popup is the only place its failure can be read,
325
325
  and `actionStandalone` there is how a save fails behind a closed popup. Something
326
326
  the app watches from somewhere else: nothing — it was never being watched here.
327
327
 
328
+ And when the answer being sent may never arrive at all — a request over a
329
+ network that stopped answering — the hold outlives what it was protecting:
330
+ nothing can close the popup, ever. `actionAbortable` keeps the hold and gives it
331
+ a release, so closing calls the run off rather than being refused. What that
332
+ costs, and where it may be said, is
333
+ [popup_open.md](./popup_open.md#the-popup-owns-its-open-state).
334
+
328
335
  ### On something you draw yourself
329
336
 
330
337
  `selfInteractions` is a `Box` prop too, so an affordance does not have to become
@@ -29,10 +29,10 @@ something a `useState` in the parent cannot give back: **a popup refuses to
29
29
  close while a control inside it is mid-action**.
30
30
 
31
31
  ```js
32
- // what both do on every close request
33
- const busyElement = findBusyElementInside(popupEl);
34
- if (busyElement) {
35
- dispatchRequestInteraction(busyElement, { ... });
32
+ // what both do on every close request (popup_busy.js)
33
+ const controlsHolding = findControlsHoldingPopup(popupEl);
34
+ if (controlsHolding.length) {
35
+ dispatchRequestInteraction(controlsHolding[0].element, { ... });
36
36
  requestCloseEvent.preventDefault();
37
37
  }
38
38
  ```
@@ -58,6 +58,33 @@ It is still busy for itself — the spinner, the second press refused, the error
58
58
  callout — which is the whole point of keeping `action` (see
59
59
  [interactions.md](./interactions.md#the-fourth-question-whose-wait-is-it)).
60
60
 
61
+ Between the two sits a run that IS being waited on and may never end. A request
62
+ over a network that stopped answering settles neither way, and the hold then
63
+ lasts exactly as long as the run: the popup closes for nothing and nobody, and
64
+ the page has to be reloaded. `actionAbortable` gives that hold a release — the
65
+ person waiting decides the answer is not coming, and closing is how they say
66
+ it:
67
+
68
+ ```jsx
69
+ <Form action={saveScore} actionAbortable>
70
+ ```
71
+
72
+ Every close request then goes through and calls the run off on the way out:
73
+ Escape, the backdrop, the cross, the phone's back gesture. No gesture is singled
74
+ out, because the cancel/keep distinction below is about the VALUE a popup holds,
75
+ and there is nothing left to keep or put back once the answer is already on the
76
+ wire — each of those gestures means "I want out of here", which is the only
77
+ thing being answered.
78
+
79
+ What it costs is written down: aborting frees the client and nothing more, so
80
+ the write may have landed anyway (see
81
+ [actions.md](./actions.md#aborting-saves-resources-it-does-not-undo)). Say it
82
+ where the screen can be re-opened on what is actually there, never where the
83
+ popup is the only place the outcome could be read. Everything inside the form
84
+ inherits it along with the wait itself; a popup holding one run that may be
85
+ given up on and one that may not still refuses, since calling off half of them
86
+ would cost an answer and change nothing on screen.
87
+
61
88
  So the question is never "should this popup be controlled?" but "what triggers
62
89
  the opening?" — and, when the answer is the application rather than a gesture,
63
90
  where that state lives:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/navi",
3
- "version": "0.29.226",
3
+ "version": "0.29.227",
4
4
  "type": "module",
5
5
  "description": "Library of components including navigation to create frontend applications",
6
6
  "repository": {