@kayjs/kay 1.107.0 → 1.108.0
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.
- package/dist/eslint.js +50 -29
- package/editors/zed/extension.toml +2 -2
- package/llms/actions-from-islands.md +1 -1
- package/llms/component-libraries.md +1 -1
- package/llms/deprecated-lints.md +0 -1
- package/llms/islands.md +1 -1
- package/llms/upgrading.md +6 -0
- package/llms/whats-new-archive.md +36 -1
- package/llms/whats-new.md +9 -39
- package/llms.txt +1 -1
- package/package.json +6 -6
- package/src/build/client.ts +7 -6
- package/src/build/icon-slots.ts +140 -0
- package/src/build/libraries.ts +24 -2
- package/src/build/plugin.ts +10 -0
- package/src/build/runtime-chunk.ts +2 -2
- package/src/build/source-files.ts +8 -3
- package/src/build/variants.ts +90 -1
- package/src/check/project.ts +4 -4
- package/src/check/renamed-packages.ts +3 -63
- package/src/check/shadow-types.ts +4 -18
- package/src/compiler/dead-code.ts +22 -0
- package/src/compiler/deprecated-lints.ts +1 -10
- package/src/compiler/dom-property.ts +23 -0
- package/src/compiler/dom.ts +15 -15
- package/src/package-names.ts +1 -1
- package/src/runtime/action-call.ts +39 -327
- package/src/runtime/action-run.ts +357 -0
- package/types/build/client.d.ts +1 -1
- package/types/build/client.d.ts.map +1 -1
- package/types/build/icon-slots.d.ts +7 -0
- package/types/build/icon-slots.d.ts.map +1 -0
- package/types/build/libraries.d.ts +2 -0
- package/types/build/libraries.d.ts.map +1 -1
- package/types/build/plugin.d.ts +1 -0
- package/types/build/plugin.d.ts.map +1 -1
- package/types/build/source-files.d.ts.map +1 -1
- package/types/build/variants.d.ts.map +1 -1
- package/types/check/renamed-packages.d.ts +0 -3
- package/types/check/renamed-packages.d.ts.map +1 -1
- package/types/check/shadow-types.d.ts.map +1 -1
- package/types/compiler/dead-code.d.ts +9 -0
- package/types/compiler/dead-code.d.ts.map +1 -0
- package/types/compiler/deprecated-lints.d.ts +0 -9
- package/types/compiler/deprecated-lints.d.ts.map +1 -1
- package/types/compiler/dom-property.d.ts +9 -0
- package/types/compiler/dom-property.d.ts.map +1 -0
- package/types/compiler/dom.d.ts +1 -0
- package/types/compiler/dom.d.ts.map +1 -1
- package/types/compiler/lints.d.ts +0 -9
- package/types/compiler/lints.d.ts.map +1 -1
- package/types/runtime/action-call.d.ts.map +1 -1
- package/types/runtime/action-run.d.ts +23 -0
- package/types/runtime/action-run.d.ts.map +1 -0
|
@@ -1,24 +1,20 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Lane, Start } from './action-run'
|
|
2
2
|
import type { Action, ActionErrorDetail, ActionStartDetail, ActionStream, ActionSuccessDetail, CallOptions, CallQueue, Outcome, TrackedCall } from './action-shared'
|
|
3
3
|
import type { ApiError } from './api-error'
|
|
4
4
|
import type { CallPromise, CallResult, TrackHooks } from './call-result'
|
|
5
|
-
import type {
|
|
6
|
-
import type { ConnectionStatus, LoadStatus } from './live'
|
|
5
|
+
import type { LoadStatus } from './live'
|
|
7
6
|
import { ActionError, ActionRedirectError } from './action-error'
|
|
8
7
|
import { PAYLOAD_PARAM, payloadQuery, withFields } from './action-form'
|
|
9
8
|
import { networkFailures, refusedAt, superseding } from './action-marks'
|
|
10
|
-
import {
|
|
11
|
-
import { onStreamEnd, SETTLED } from './action-owner'
|
|
9
|
+
import { onStreamEnd } from './action-owner'
|
|
12
10
|
import { ACTION } from './action-shared'
|
|
13
|
-
import { actionFailed,
|
|
11
|
+
import { actionFailed, failed, messageOf, unreachable } from './api-error'
|
|
14
12
|
import { withoutBase } from './base'
|
|
15
13
|
import { skew } from './build'
|
|
16
14
|
import { settling, signalAborted, trackCalls, whenIdle } from './call-result'
|
|
17
|
-
import { durationSeconds, isZeroDuration } from './duration'
|
|
18
15
|
import { navigation } from './navigation'
|
|
19
16
|
import { released, undoable } from './optimistic'
|
|
20
17
|
import { pageData } from './page-data'
|
|
21
|
-
import { randomId } from './random-id'
|
|
22
18
|
import { getOwner, liveOwner, onCleanup, ownSignal, untrack } from './reactive'
|
|
23
19
|
import { OUTCOME_SCRIPT } from './swap'
|
|
24
20
|
import { ACTION_PREFIX, ACTION_TYPE, decodeServerValue, FIXED_FIELDS, malformed, serverWritten } from './wire'
|
|
@@ -30,122 +26,14 @@ export { OUTCOME_SCRIPT }
|
|
|
30
26
|
|
|
31
27
|
const QUERY = /\?.*/
|
|
32
28
|
|
|
33
|
-
// A property of the handle an action builds, readable and listed.
|
|
34
|
-
const read = (value: unknown) => ({ value, enumerable: true })
|
|
35
|
-
|
|
36
|
-
const RETRY_DELAY_MS = 500
|
|
37
29
|
const CODE_RETRIES = 2
|
|
38
|
-
// Once loaded, a call is
|
|
39
|
-
let
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return randomId()
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// The calls of an action, or of one `track()` handle, that `queue` orders: `tail` settles when the last `serial` call is done, `latest` is the call in flight a newer one aborts.
|
|
46
|
-
interface Lane {
|
|
47
|
-
tail: Promise<unknown>
|
|
48
|
-
queue?: CallQueue | undefined
|
|
49
|
-
latest?: AbortController | undefined
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// One signal for several, aborting with the reason of the first to abort. A lone one is returned as it is, so a browser that has no `AbortSignal.any` still runs the call; `stop` lets go of the listeners, and `always` makes a signal of its own whose sources can be let go of before the call ends.
|
|
53
|
-
function join(sources: (AbortSignal | undefined)[], always = false): { signal: AbortSignal | undefined, stop: (only?: AbortSignal) => void } {
|
|
54
|
-
const list = sources.filter(source => source !== undefined)
|
|
55
|
-
|
|
56
|
-
if (list.length < 2 && !always)
|
|
57
|
-
return { signal: list[0], stop: () => undefined }
|
|
58
|
-
|
|
59
|
-
const controller = new AbortController()
|
|
60
|
-
const forwards = list.map(source => [source, () => controller.abort(source.reason)] as const)
|
|
61
|
-
|
|
62
|
-
for (const [source, forward] of forwards) {
|
|
63
|
-
if (source.aborted) {
|
|
64
|
-
controller.abort(source.reason)
|
|
65
|
-
|
|
66
|
-
break
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
source.addEventListener('abort', forward, { once: true })
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return {
|
|
73
|
-
signal: controller.signal,
|
|
74
|
-
stop: (only) => {
|
|
75
|
-
for (const [source, forward] of forwards) {
|
|
76
|
-
if (only === undefined || only === source)
|
|
77
|
-
source.removeEventListener('abort', forward)
|
|
78
|
-
}
|
|
79
|
-
},
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// Waits for `ms`, or for the calls ahead when given a promise, giving up at once when the signal aborts meanwhile.
|
|
84
|
-
async function waitFor(wait: number | Promise<unknown>, signal: AbortSignal | undefined): Promise<void> {
|
|
85
|
-
signal?.throwIfAborted()
|
|
86
|
-
|
|
87
|
-
let stop = () => undefined as void
|
|
88
|
-
|
|
89
|
-
try {
|
|
90
|
-
await new Promise<unknown>((resolve, reject) => {
|
|
91
|
-
const abort = () => reject(signal!.reason)
|
|
92
|
-
const id = typeof wait === 'number' ? setTimeout(resolve, wait) : undefined
|
|
93
|
-
|
|
94
|
-
if (typeof wait !== 'number') {
|
|
95
|
-
void (async () => {
|
|
96
|
-
try {
|
|
97
|
-
resolve(await wait)
|
|
98
|
-
}
|
|
99
|
-
catch (error) {
|
|
100
|
-
reject(error)
|
|
101
|
-
}
|
|
102
|
-
})()
|
|
103
|
-
}
|
|
30
|
+
// Once loaded, a call is made in the same task, as one made from `pagehide` must be: a dynamic import resolves a task later, when the page may be gone.
|
|
31
|
+
let running: typeof import('./action-run') | undefined
|
|
32
|
+
// The load the calls made before it ends share, so they go on in the order they were made.
|
|
33
|
+
let loading: Promise<typeof import('./action-run')> | undefined
|
|
104
34
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
clearTimeout(id)
|
|
108
|
-
signal?.removeEventListener('abort', abort)
|
|
109
|
-
}
|
|
110
|
-
})
|
|
111
|
-
}
|
|
112
|
-
finally {
|
|
113
|
-
stop()
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// How long a wait of the call's lasts: nothing for a zero, a clear error for text that is no duration.
|
|
118
|
-
function waitOf(value: Duration | undefined, what: string): number | undefined {
|
|
119
|
-
return value === undefined || isZeroDuration(value) ? undefined : durationSeconds(value, what) * 1000
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// Whether a failure is one a retry may repeat: the server's answer or the network's failure, never a redirect, an abort or something thrown before the post was sent. Unless `when` says otherwise, a 503 (the server turned the call away) and a failure before the post was sent are, and nothing else, as a post that reached the server may have run.
|
|
123
|
-
function retryOf(retry: CallOptions['retry']): { times: number, delay: number, again: (error: unknown, sent: boolean) => boolean } {
|
|
124
|
-
const options = typeof retry === 'number' ? { times: retry } : retry
|
|
125
|
-
|
|
126
|
-
return {
|
|
127
|
-
times: options?.times ?? 0,
|
|
128
|
-
delay: waitOf(options?.delay, 'retry.delay') ?? RETRY_DELAY_MS,
|
|
129
|
-
again: (error, sent) => {
|
|
130
|
-
if (error instanceof ActionRedirectError || !(error instanceof ActionError || networkFailures.has(error as object) || (error as { name?: unknown } | null)?.name === 'TimeoutError'))
|
|
131
|
-
return false
|
|
132
|
-
|
|
133
|
-
const failure = apiErrorOf(error)
|
|
134
|
-
|
|
135
|
-
return options?.when ? options.when(failure) : failure.status === 503 || (!sent && (failure.status === 0 || failure.status === 502))
|
|
136
|
-
},
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
// A hook never fails the call it observes: a throw, or a rejection, is logged.
|
|
141
|
-
async function hooked<Event>(hook: ((event: Event) => unknown) | undefined, event: Event): Promise<void> {
|
|
142
|
-
try {
|
|
143
|
-
await hook?.(event)
|
|
144
|
-
}
|
|
145
|
-
catch (error) {
|
|
146
|
-
console.error(error)
|
|
147
|
-
}
|
|
148
|
-
}
|
|
35
|
+
// A property of the handle an action builds, readable and listed.
|
|
36
|
+
const read = (value: unknown) => ({ value, enumerable: true })
|
|
149
37
|
|
|
150
38
|
// On the server, the form post the request being answered carries: null for none, undefined outside a request.
|
|
151
39
|
let requestOutcome: (() => Outcome | null | undefined) | undefined
|
|
@@ -221,32 +109,6 @@ function lazySignal<T>(value: T): [read: () => T, write: (next: T) => void, peek
|
|
|
221
109
|
}, () => current]
|
|
222
110
|
}
|
|
223
111
|
|
|
224
|
-
// A call of an action `with()` fixed fields of is made with them, over the ones it is given, as a form posting to its URL does: a field fixed to `null` or `undefined` is left out there, so the given one stays.
|
|
225
|
-
function withFixed(input: unknown, fixed: Record<string, unknown> | undefined): unknown {
|
|
226
|
-
if (fixed === undefined)
|
|
227
|
-
return input
|
|
228
|
-
|
|
229
|
-
const set = Object.entries(fixed).filter(([name, value]) => name !== '__proto__' && value !== undefined && value !== null)
|
|
230
|
-
|
|
231
|
-
if (!(input instanceof FormData))
|
|
232
|
-
return { ...input as object | undefined, ...Object.fromEntries(set) }
|
|
233
|
-
|
|
234
|
-
const names = new Set(set.map(([name]) => name))
|
|
235
|
-
const copy = new FormData()
|
|
236
|
-
|
|
237
|
-
for (const [name, value] of input) {
|
|
238
|
-
if (!names.has(name))
|
|
239
|
-
copy.append(name, value)
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
for (const [name, value] of set) {
|
|
243
|
-
for (const item of Array.isArray(value) ? value : [value])
|
|
244
|
-
copy.append(name, item instanceof Date ? item.toISOString() : String(item))
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
return copy
|
|
248
|
-
}
|
|
249
|
-
|
|
250
112
|
// Checks a form against the action's schema in the browser, as the server would, and hands `show` the messages to read as a refusal's, undefined for none; one field checked replaces that field's message and leaves the others.
|
|
251
113
|
function validator(url: () => string, failed: () => { errors: Record<string, string> } | undefined, show: (errors: Record<string, string> | undefined) => unknown): (form: HTMLFormElement, field?: string) => Promise<boolean> {
|
|
252
114
|
return async (form, field) => {
|
|
@@ -264,7 +126,7 @@ function validator(url: () => string, failed: () => { errors: Record<string, str
|
|
|
264
126
|
}
|
|
265
127
|
}
|
|
266
128
|
|
|
267
|
-
//
|
|
129
|
+
// Makes the call of an action, counting the ones in flight; a call that redirects rejects with `ActionRedirectError` once the browser is on its way, so the action stops being pending.
|
|
268
130
|
// How a post went is the request's on the server; in the browser the last call's once the page shown made one, else the post the page answers.
|
|
269
131
|
export function callable(url: () => string): { call: (input: never, options?: CallOptions) => CallPromise<CallResult<unknown, unknown>>, reads: PropertyDescriptorMap, bound: Bound } {
|
|
270
132
|
const [inFlight, setInFlight, flying] = lazySignal(0)
|
|
@@ -294,187 +156,41 @@ export function callable(url: () => string): { call: (input: never, options?: Ca
|
|
|
294
156
|
}
|
|
295
157
|
const error = (field = '') => failed()?.errors[field]
|
|
296
158
|
const validate = validator(url, failed, errors => called(navigation.page, errors === undefined ? null : { action: url(), status: 422, values: {}, errors, data: undefined }))
|
|
159
|
+
const host = { url, shift, called, progress: setProgress, latest: (turn: number) => turn === started }
|
|
297
160
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
const
|
|
301
|
-
const visits = navigation.visits
|
|
302
|
-
const left = () => navigation.visits !== visits
|
|
303
|
-
// The island calling, from its setup or a handler, whose end ends a stream the call answers with; else the page, as long as no other path is shown.
|
|
304
|
-
const caller: Caller = { owner: liveOwner(getOwner()), arrivals: navigation.arrivals }
|
|
305
|
-
const mode = options?.queue ?? lane.queue ?? 'parallel'
|
|
306
|
-
|
|
307
|
-
const turn = ++started
|
|
161
|
+
// The state a call changes is the action's own and is read from the first paint, so a call counts itself in flight at once and hands the rest to the code that runs it, which loads with the first call.
|
|
162
|
+
const run = async (lane: Lane, input: unknown, fixed: Record<string, unknown> | undefined, options?: CallOptions) => {
|
|
163
|
+
const start: Start = { page: navigation.page, visits: navigation.visits, caller: { owner: liveOwner(getOwner()), arrivals: navigation.arrivals }, turn: ++started }
|
|
308
164
|
|
|
309
165
|
shift(1)
|
|
310
|
-
called(page, null)
|
|
311
|
-
void hooked(options?.onStart, { input })
|
|
312
|
-
|
|
313
|
-
let undo: (() => void) | undefined
|
|
314
|
-
let posted = false
|
|
315
|
-
let sent = false
|
|
316
|
-
let timedOut = false
|
|
317
|
-
// A stream keeps the call in flight until it ends.
|
|
318
|
-
let streaming = false
|
|
319
|
-
let answer: unknown
|
|
320
|
-
let failure: unknown
|
|
321
|
-
let release: (() => void) | undefined
|
|
322
|
-
// Started before the caller goes on, so a navigation it starts next supersedes the refresh rather than the other way round; a site with `navigation: false` shows a call's effects itself.
|
|
323
|
-
const refreshPage = () => {
|
|
324
|
-
const scope = options?.refresh
|
|
325
|
-
|
|
326
|
-
if (scope === false || left())
|
|
327
|
-
return
|
|
166
|
+
called(start.page, null)
|
|
328
167
|
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
void (scope === true ? refreshed() : refreshedUnlessFollowed(caller.invalidated))
|
|
332
|
-
}
|
|
333
|
-
else {
|
|
334
|
-
const asked = [scope].flat()
|
|
335
|
-
const names = asked.filter(source => typeof source === 'string')
|
|
336
|
-
|
|
337
|
-
if (names.length > 0 && navigation.hooks)
|
|
338
|
-
void refreshed(names)
|
|
339
|
-
|
|
340
|
-
void refreshedIn(asked.filter(source => typeof source !== 'string'))
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
const later = mode === 'latest' ? new AbortController() : undefined
|
|
344
|
-
// What aborts the call as a whole: its own signal, and a later call of a `latest` queue, which stops mattering once the post is answered.
|
|
345
|
-
const whole = join([options?.signal, later?.signal], later !== undefined)
|
|
346
|
-
const timeoutOption = options?.timeout
|
|
347
|
-
const timeout = waitOf(timeoutOption, 'timeout')
|
|
168
|
+
let code: typeof import('./action-run')
|
|
169
|
+
let attempt: typeof loading
|
|
348
170
|
|
|
349
171
|
try {
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
const reason = new DOMException('Superseded by a later call', 'AbortError')
|
|
354
|
-
|
|
355
|
-
superseding.add(reason)
|
|
356
|
-
lane.latest?.abort(reason)
|
|
357
|
-
lane.latest = later
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
if (mode === 'serial') {
|
|
361
|
-
const before = lane.tail
|
|
362
|
-
|
|
363
|
-
lane.tail = Promise.all([before, new Promise<void>((resolve) => {
|
|
364
|
-
release = resolve
|
|
365
|
-
})])
|
|
366
|
-
await waitFor(before, whole.signal)
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
const attempts = retryOf(options?.retry)
|
|
370
|
-
// One key for every try of the call, which a handler reads from `ctx.request` to tell a repeat from a new call.
|
|
371
|
-
const key = attempts.times > 0 ? idempotencyKey() : undefined
|
|
372
|
-
|
|
373
|
-
for (let attempt = 0; ; attempt++) {
|
|
374
|
-
// The wait for the answer counts from the moment the post is sent, and each try has its own.
|
|
375
|
-
const limit = timeout === undefined ? undefined : new AbortController()
|
|
376
|
-
const attemptSignal = join([whole.signal, limit?.signal])
|
|
377
|
-
let timer: ReturnType<typeof setTimeout> | undefined
|
|
378
|
-
let sentNow = false
|
|
379
|
-
|
|
380
|
-
try {
|
|
381
|
-
answer = await (await postingCode()).post(url(), input, setProgress, attemptSignal.signal, () => {
|
|
382
|
-
sent = sentNow = true
|
|
383
|
-
clearTimeout(timer)
|
|
384
|
-
timer = limit && setTimeout(() => {
|
|
385
|
-
timedOut = true
|
|
386
|
-
limit.abort(new DOMException(`The action call timeout of ${String(timeoutOption)} passed before the server answered`, 'TimeoutError'))
|
|
387
|
-
}, timeout)
|
|
388
|
-
}, left, caller, { key, options })
|
|
389
|
-
|
|
390
|
-
break
|
|
391
|
-
}
|
|
392
|
-
catch (error) {
|
|
393
|
-
// Only the upload path says `sent: false`, as `fetch` gives no such signal and `onSent` has run before it: the default retry of an unsent post covers an upload alone.
|
|
394
|
-
if (attempt >= attempts.times || whole.signal?.aborted === true || !attempts.again(error, sentNow && (error as { sent?: unknown } | null)?.sent !== false))
|
|
395
|
-
throw error
|
|
396
|
-
|
|
397
|
-
await waitFor(attempts.delay * 2 ** attempt, whole.signal)
|
|
398
|
-
}
|
|
399
|
-
finally {
|
|
400
|
-
clearTimeout(timer)
|
|
401
|
-
attemptSignal.stop()
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
posted = true
|
|
406
|
-
whole.stop(later?.signal)
|
|
407
|
-
release?.()
|
|
408
|
-
release = undefined
|
|
409
|
-
|
|
410
|
-
const streamEnded = (status: ConnectionStatus) => {
|
|
411
|
-
if (status === 'done') {
|
|
412
|
-
called(page, { action: url(), succeeded: true, data: untrack((answer as ActionStream<unknown>).last) }, turn)
|
|
413
|
-
refreshPage()
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
shift(-1)
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
streaming = onStreamEnd(answer, streamEnded)
|
|
420
|
-
|
|
421
|
-
if (streaming) {
|
|
422
|
-
// A retry of the stream is the call running again.
|
|
423
|
-
caller.retried = (again) => {
|
|
424
|
-
shift(1)
|
|
425
|
-
again[SETTLED](streamEnded)
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
if (!streaming) {
|
|
430
|
-
called(page, { action: url(), succeeded: true, data: answer }, turn)
|
|
431
|
-
refreshPage()
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
void hooked(options?.onSuccess, { data: answer })
|
|
435
|
-
|
|
436
|
-
return answer
|
|
172
|
+
// An optimistic change shows at once, as the call is pending at once.
|
|
173
|
+
start.undo = options?.optimistic ? undoable(options.optimistic) : undefined
|
|
174
|
+
code = running ?? await (attempt = loading ??= runCode())
|
|
437
175
|
}
|
|
438
176
|
catch (error) {
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
// A redirect leaves the page as it is until the next one shows.
|
|
442
|
-
if (!posted && !(error instanceof ActionRedirectError))
|
|
443
|
-
undo?.()
|
|
177
|
+
if (loading === attempt)
|
|
178
|
+
loading = undefined
|
|
444
179
|
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
180
|
+
if (start.undo) {
|
|
181
|
+
start.undo()
|
|
182
|
+
released(start.undo)
|
|
183
|
+
}
|
|
448
184
|
|
|
449
|
-
|
|
450
|
-
called(page, { action: url(), status: error.status, values: {}, errors: error.errors, data: error.data }, turn)
|
|
185
|
+
shift(-1)
|
|
451
186
|
|
|
452
|
-
if (
|
|
453
|
-
|
|
187
|
+
if (host.latest(start.turn))
|
|
188
|
+
setProgress(undefined)
|
|
454
189
|
|
|
455
190
|
throw error
|
|
456
191
|
}
|
|
457
|
-
finally {
|
|
458
|
-
// A stream is aborted by the call's own signal until it ends.
|
|
459
|
-
if (!streaming)
|
|
460
|
-
whole.stop()
|
|
461
|
-
|
|
462
|
-
release?.()
|
|
463
192
|
|
|
464
|
-
|
|
465
|
-
released(undo)
|
|
466
|
-
|
|
467
|
-
if (!streaming)
|
|
468
|
-
shift(-1)
|
|
469
|
-
|
|
470
|
-
if (turn === started)
|
|
471
|
-
setProgress(undefined)
|
|
472
|
-
|
|
473
|
-
if (lane.latest === later)
|
|
474
|
-
lane.latest = undefined
|
|
475
|
-
|
|
476
|
-
void hooked(options?.onSettled, failure === undefined ? { data: answer } : { error: apiErrorOf(failure) })
|
|
477
|
-
}
|
|
193
|
+
return code.run(host, start, lane, input, fixed, options)
|
|
478
194
|
}
|
|
479
195
|
|
|
480
196
|
const bound = binder(run, url)
|
|
@@ -542,16 +258,16 @@ function formHook<Detail extends { action: string }, Told>(url: () => string, st
|
|
|
542
258
|
}
|
|
543
259
|
|
|
544
260
|
// A call and `track()` carrying the fields given, over one action's state: a `with` of the action follows the same calls.
|
|
545
|
-
function binder(run: (lane: Lane, input: unknown, options?: CallOptions) => Promise<unknown>, url: () => string): Bound {
|
|
261
|
+
function binder(run: (lane: Lane, input: unknown, fixed: Record<string, unknown> | undefined, options?: CallOptions) => Promise<unknown>, url: () => string): Bound {
|
|
546
262
|
const actionLane: Lane = { tail: Promise.resolve() }
|
|
547
263
|
|
|
548
264
|
return fields => ({
|
|
549
265
|
// eslint-disable-next-line ts/promise-function-async -- an async function would wrap the call's promise, which carries `orThrow()`
|
|
550
|
-
call: (input: unknown, options?: CallOptions) => settling(run(actionLane,
|
|
266
|
+
call: (input: unknown, options?: CallOptions) => settling(run(actionLane, input, fields, options), error => signalAborted(options) ? undefined : refusalOf(url)(error)),
|
|
551
267
|
track: (handle) => {
|
|
552
268
|
const lane: Lane = { tail: Promise.resolve(), queue: handle?.queue }
|
|
553
269
|
|
|
554
|
-
return tracked(async (input, options) => run(lane,
|
|
270
|
+
return tracked(async (input, options) => run(lane, input, fields, options), url, handle)
|
|
555
271
|
},
|
|
556
272
|
})
|
|
557
273
|
}
|
|
@@ -599,7 +315,7 @@ function tracked(call: (input: never, options?: CallOptions) => Promise<unknown>
|
|
|
599
315
|
|
|
600
316
|
let warming = false
|
|
601
317
|
|
|
602
|
-
// An island holding an action caller loads the
|
|
318
|
+
// An island holding an action caller loads the code running a call once the browser is idle, so a call made as the page goes away (`pagehide`, which cannot wait for a chunk) finds it in; it stays out of the first load. A failure is left for the call itself to retry and report, so an idle load never reloads the page.
|
|
603
319
|
function warmCode(): void {
|
|
604
320
|
if (warming || typeof window === 'undefined')
|
|
605
321
|
return
|
|
@@ -608,7 +324,7 @@ function warmCode(): void {
|
|
|
608
324
|
|
|
609
325
|
const load = async () => {
|
|
610
326
|
try {
|
|
611
|
-
|
|
327
|
+
running = await import('./action-run')
|
|
612
328
|
}
|
|
613
329
|
catch {}
|
|
614
330
|
}
|
|
@@ -619,15 +335,11 @@ function warmCode(): void {
|
|
|
619
335
|
setTimeout(() => void load(), 200)
|
|
620
336
|
}
|
|
621
337
|
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
// A flaky connection gets the chunk retried after 1 s and 3 s, as a lazy component's is. The code that posts a call, loaded by the first call; a chunk a deploy removed asks the server whether the build changed, which reloads the page, and the call fails as any call that could not be sent.
|
|
627
|
-
async function postCode(): Promise<typeof import('./action-post')> {
|
|
338
|
+
// A flaky connection gets the chunk retried after 1 s and 3 s, as a lazy component's is. The code that runs a call, loaded by the first call; a chunk a deploy removed asks the server whether the build changed, which reloads the page, and the call fails as any call that could not be sent.
|
|
339
|
+
async function runCode(): Promise<typeof import('./action-run')> {
|
|
628
340
|
for (let attempt = 0; ; attempt++) {
|
|
629
341
|
try {
|
|
630
|
-
return
|
|
342
|
+
return running = await import('./action-run')
|
|
631
343
|
}
|
|
632
344
|
catch (error) {
|
|
633
345
|
if (attempt >= CODE_RETRIES) {
|