@fullstackunicorn/webapp 2.0.4 → 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/use.js +3 -3
- package/native/imports/client.js +2 -1
- package/package.json +1 -1
- package/package.md +2 -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/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
|
@@ -18,6 +18,8 @@ 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
19
|
The resource-ready state is committed before content initialization, while the
|
|
20
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.
|
|
21
23
|
The shared
|
|
22
24
|
`Img` component measures its mounted container, treats `src + hash` as binary
|
|
23
25
|
identity and keeps the decoded displayed image visible until a changed pending
|