@fullstackunicorn/webapp 2.0.3 → 2.0.5
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/imports/client.js +2 -1
- package/imports/request.js +12 -0
- package/load/Load.js +8 -4
- package/load/engine.js +8 -4
- package/load/resources.js +1 -1
- package/load/use.js +3 -3
- package/native/imports/client.js +2 -1
- package/package.json +1 -1
- package/package.md +4 -0
package/imports/client.js
CHANGED
|
@@ -3,6 +3,7 @@ import { constants } from '#@/root/constants.js'
|
|
|
3
3
|
import { abs } from '#@/abstracts/abs.js'
|
|
4
4
|
import { err } from '#@/abstracts/err.js'
|
|
5
5
|
import { cache } from '#imports/cache.js'
|
|
6
|
+
import { requestFailure } from '#imports/request.js'
|
|
6
7
|
|
|
7
8
|
class Client {
|
|
8
9
|
|
|
@@ -31,7 +32,7 @@ class Client {
|
|
|
31
32
|
const validated = this.validate({ response, is: { post: true } })
|
|
32
33
|
if (!validated.isValid) return validated
|
|
33
34
|
return response.data
|
|
34
|
-
} catch (error) { return await err.handle(
|
|
35
|
+
} catch (error) { return await requestFailure(error, value => err.handle(value)) }
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
graphQl = async (payload = {}, isNoCache) => {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const isCancellation = error => error?.name === 'AbortError'
|
|
2
|
+
|| error?.name === 'CanceledError'
|
|
3
|
+
|| error?.code === 'ERR_CANCELED'
|
|
4
|
+
|
|
5
|
+
export const requestFailure = (error, fallback) => {
|
|
6
|
+
if (!isCancellation(error)) return fallback(error)
|
|
7
|
+
if (error.name === 'AbortError') throw error
|
|
8
|
+
const aborted = new Error(error.message || 'Aborted')
|
|
9
|
+
aborted.name = 'AbortError'
|
|
10
|
+
aborted.cause = error
|
|
11
|
+
throw aborted
|
|
12
|
+
}
|
package/load/Load.js
CHANGED
|
@@ -15,9 +15,13 @@ export const Load = ({ onReady = ready }) => {
|
|
|
15
15
|
|
|
16
16
|
const { lang } = useUrl()
|
|
17
17
|
const refresh = useRefreshContent()
|
|
18
|
+
const refreshRef = useRef(refresh)
|
|
19
|
+
const onReadyRef = useRef(onReady)
|
|
18
20
|
const dimensions = useWindowDimensions()
|
|
19
21
|
const geometry = loadGeometry.signature(dimensions.width, img.pixelRatio())
|
|
20
22
|
const dimensionsRef = useRef(dimensions)
|
|
23
|
+
refreshRef.current = refresh
|
|
24
|
+
onReadyRef.current = onReady
|
|
21
25
|
dimensionsRef.current = dimensions
|
|
22
26
|
|
|
23
27
|
useEffect(() => {
|
|
@@ -36,15 +40,15 @@ export const Load = ({ onReady = ready }) => {
|
|
|
36
40
|
if (!active) return
|
|
37
41
|
await engine.run(lang, dimensionsRef.current.width, controller.signal, async refreshNeeded => {
|
|
38
42
|
if (prepared || !active) return
|
|
39
|
-
if (refreshNeeded) await
|
|
43
|
+
if (refreshNeeded) await refreshRef.current(lang)
|
|
40
44
|
if (active) {
|
|
41
45
|
prepared = true
|
|
42
|
-
|
|
46
|
+
onReadyRef.current(true)
|
|
43
47
|
}
|
|
44
48
|
})
|
|
45
49
|
if (!prepared && active) {
|
|
46
50
|
prepared = true
|
|
47
|
-
|
|
51
|
+
onReadyRef.current(true)
|
|
48
52
|
}
|
|
49
53
|
} catch (error) { if (error.name !== 'AbortError') console.error('load-failed', error) }
|
|
50
54
|
finally {
|
|
@@ -66,7 +70,7 @@ export const Load = ({ onReady = ready }) => {
|
|
|
66
70
|
clearTimeout(timer)
|
|
67
71
|
stop()
|
|
68
72
|
}
|
|
69
|
-
}, [lang, geometry
|
|
73
|
+
}, [lang, geometry])
|
|
70
74
|
|
|
71
75
|
return null
|
|
72
76
|
}
|
package/load/engine.js
CHANGED
|
@@ -40,7 +40,8 @@ class Engine {
|
|
|
40
40
|
|
|
41
41
|
changed = async lang => {
|
|
42
42
|
const [current, previous] = await Promise.all([this.pulse(lang), get(this.key(lang))])
|
|
43
|
-
|
|
43
|
+
const resourcesReady = previous?.resources === true || previous?.complete === true
|
|
44
|
+
return !resourcesReady || this.signature(previous.state) !== this.signature(current)
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
run = async (lang, width, signal, onResources) => {
|
|
@@ -84,12 +85,15 @@ class Engine {
|
|
|
84
85
|
const item = typeof value === 'string' ? before.items?.[value] : value
|
|
85
86
|
return item?.kind === 'resource'
|
|
86
87
|
})
|
|
87
|
-
nextItems = await resources.apply(preload, width, nextItems, signal,
|
|
88
|
-
|
|
88
|
+
nextItems = await resources.apply(preload, width, nextItems, signal, async resourceItems => {
|
|
89
|
+
await set(key, { state: response.current, complete: false, resources: true, items: resourceItems, geometry })
|
|
90
|
+
await onResources?.(refresh)
|
|
91
|
+
})
|
|
92
|
+
await set(key, { state: response.current, complete: true, resources: true, items: nextItems, geometry })
|
|
89
93
|
} else if (geometryChanged) {
|
|
90
94
|
await onResources?.(false)
|
|
91
95
|
nextItems = await resources.resize(nextItems, width, signal)
|
|
92
|
-
await set(key, { ...before, state: current, complete: true, items: nextItems, geometry })
|
|
96
|
+
await set(key, { ...before, state: current, complete: true, resources: true, items: nextItems, geometry })
|
|
93
97
|
} else {
|
|
94
98
|
await onResources?.(false)
|
|
95
99
|
await set(key, { ...before, state: current })
|
package/load/resources.js
CHANGED
|
@@ -77,7 +77,7 @@ class Resources {
|
|
|
77
77
|
await client.cacheDataSet({ endpoint: resource.url(item.path), value: item.value, version: item.sha256 })
|
|
78
78
|
next[item.key] = item
|
|
79
79
|
})
|
|
80
|
-
await onResources?.()
|
|
80
|
+
await onResources?.(next)
|
|
81
81
|
|
|
82
82
|
const pictures = changed.filter(item => item.kind === 'image')
|
|
83
83
|
await this.queue(pictures, images.concurrency, async item => {
|
package/load/use.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { atom, useGetAtom, useSetAtom } from '#dep'
|
|
1
|
+
import { atom, useCallback, useGetAtom, useSetAtom } from '#dep'
|
|
2
2
|
import { tools } from '#@/base/loader/@tools.js'
|
|
3
3
|
import { useSetStatics } from '#@/base/statics/@use.js'
|
|
4
4
|
import { useSetLookups } from '#@/base/lookups/@use.js'
|
|
@@ -10,10 +10,10 @@ export const useRefreshContent = () => {
|
|
|
10
10
|
const setRevision = useSetAtom(revision)
|
|
11
11
|
const setStatics = useSetStatics()
|
|
12
12
|
const setLookups = useSetLookups()
|
|
13
|
-
return async lang => {
|
|
13
|
+
return useCallback(async lang => {
|
|
14
14
|
const data = await tools.loadData(lang)
|
|
15
15
|
setStatics(data.statics)
|
|
16
16
|
setLookups(data.lookups)
|
|
17
17
|
setRevision(value => value + 1)
|
|
18
|
-
}
|
|
18
|
+
}, [setLookups, setRevision, setStatics])
|
|
19
19
|
}
|
package/native/imports/client.js
CHANGED
|
@@ -3,6 +3,7 @@ import { constants } from '#@/root/constants.js'
|
|
|
3
3
|
import { abs } from '#@/abstracts/abs.js'
|
|
4
4
|
import { err } from '#@/abstracts/err.js'
|
|
5
5
|
import { cache } from '#imports/cache.js'
|
|
6
|
+
import { requestFailure } from '../../imports/request.js'
|
|
6
7
|
|
|
7
8
|
// Same surface as the web client. On native a fetched "blob"
|
|
8
9
|
// is a FileBlob ({ uri, size, type, text() }) persisted on disk,
|
|
@@ -35,7 +36,7 @@ class Client {
|
|
|
35
36
|
const validated = this.validate({ response, is: { post: true } })
|
|
36
37
|
if (!validated.isValid) return validated
|
|
37
38
|
return response.data
|
|
38
|
-
} catch (error) { return await err.handle(
|
|
39
|
+
} catch (error) { return await requestFailure(error, value => err.handle(value)) }
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
graphQl = async (payload = {}, isNoCache) => {
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "2.0.
|
|
2
|
+
"version": "2.0.5",
|
|
3
3
|
"name": "@fullstackunicorn/webapp",
|
|
4
4
|
"author": "lucanigido (https://fullstackunicorn.dev/author/lucanigido)",
|
|
5
5
|
"description": "Shared Web and Native runtime engines and core components for Fullstack Unicorn applications",
|
package/package.md
CHANGED
|
@@ -16,6 +16,10 @@ binary is actually present at the declared version in browser cache. Hosts may u
|
|
|
16
16
|
the `Load` component's `onReady` callback to initialize page content only after
|
|
17
17
|
the required JSON resources have been reconciled. Image warming continues in
|
|
18
18
|
parallel and shares the same requests and cache with mounted `Img` components.
|
|
19
|
+
The resource-ready state is committed before content initialization, while the
|
|
20
|
+
complete state is committed only after image warming finishes.
|
|
21
|
+
Parent renders keep the active Load job alive, and a cancelled request propagates
|
|
22
|
+
as `AbortError` instead of being validated as a Data bundle.
|
|
19
23
|
The shared
|
|
20
24
|
`Img` component measures its mounted container, treats `src + hash` as binary
|
|
21
25
|
identity and keeps the decoded displayed image visible until a changed pending
|