@fullstackunicorn/webapp 2.0.2 → 2.0.4

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/load/Load.js CHANGED
@@ -23,7 +23,7 @@ export const Load = ({ onReady = ready }) => {
23
23
  useEffect(() => {
24
24
  let active = true
25
25
  const controller = new AbortController()
26
- let timer, running = false
26
+ let timer, running = false, prepared = false
27
27
  const schedule = () => {
28
28
  clearTimeout(timer)
29
29
  if (active && visibility.isVisible()) timer = setTimeout(check, engine.interval)
@@ -34,10 +34,18 @@ export const Load = ({ onReady = ready }) => {
34
34
  try {
35
35
  await priority.ready()
36
36
  if (!active) return
37
- if (await engine.run(lang, dimensionsRef.current.width, controller.signal)) {
38
- if (active) await refresh(lang)
37
+ await engine.run(lang, dimensionsRef.current.width, controller.signal, async refreshNeeded => {
38
+ if (prepared || !active) return
39
+ if (refreshNeeded) await refresh(lang)
40
+ if (active) {
41
+ prepared = true
42
+ onReady(true)
43
+ }
44
+ })
45
+ if (!prepared && active) {
46
+ prepared = true
47
+ onReady(true)
39
48
  }
40
- if (active) onReady(true)
41
49
  } catch (error) { if (error.name !== 'AbortError') console.error('load-failed', error) }
42
50
  finally {
43
51
  running = false
package/load/engine.js CHANGED
@@ -40,19 +40,20 @@ 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
- return !previous?.complete || this.signature(previous.state) !== this.signature(current)
43
+ const resourcesReady = previous?.resources === true || previous?.complete === true
44
+ return !resourcesReady || this.signature(previous.state) !== this.signature(current)
44
45
  }
45
46
 
46
- run = async (lang, width, signal) => {
47
+ run = async (lang, width, signal, onResources) => {
47
48
  const previous = this.jobs.get(lang)
48
49
  if (previous) await previous.catch(error => { if (error.name !== 'AbortError') throw error })
49
50
  if (signal?.aborted) throw new DOMException('Aborted', 'AbortError')
50
- const job = this.check(lang, width, signal).finally(() => { if (this.jobs.get(lang) === job) this.jobs.delete(lang) })
51
+ const job = this.check(lang, width, signal, onResources).finally(() => { if (this.jobs.get(lang) === job) this.jobs.delete(lang) })
51
52
  this.jobs.set(lang, job)
52
53
  return job
53
54
  }
54
55
 
55
- check = async (lang, width, signal) => {
56
+ check = async (lang, width, signal, onResources) => {
56
57
  await cache.initialize()
57
58
  const key = this.key(lang)
58
59
  const before = await get(key) || { state: null, complete: false, items: {}, geometry: null }
@@ -80,16 +81,21 @@ class Engine {
80
81
  const preload = response?.preload
81
82
  if (!response?.current?.site || !preload || !Array.isArray(preload.delete)
82
83
  || !Array.isArray(preload.replace) || !Array.isArray(preload.new)) throw new Error('Invalid Data load bundle')
83
- nextItems = await resources.apply(preload, width, nextItems, signal)
84
84
  refresh = [...preload.delete, ...preload.replace, ...preload.new].some(value => {
85
85
  const item = typeof value === 'string' ? before.items?.[value] : value
86
86
  return item?.kind === 'resource'
87
87
  })
88
- await set(key, { state: response.current, complete: true, items: nextItems, geometry })
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) {
94
+ await onResources?.(false)
90
95
  nextItems = await resources.resize(nextItems, width, signal)
91
- 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 })
92
97
  } else {
98
+ await onResources?.(false)
93
99
  await set(key, { ...before, state: current })
94
100
  }
95
101
 
package/load/resources.js CHANGED
@@ -63,7 +63,7 @@ class Resources {
63
63
  return { ...item, size: selected.size, url: selected.src, version: selected.version, hash: selected.hash }
64
64
  }
65
65
 
66
- apply = async (preload, width, current = {}, signal) => {
66
+ apply = async (preload, width, current = {}, signal, onResources) => {
67
67
  const next = { ...current }
68
68
  for (const key of preload.delete || []) {
69
69
  await this.remove(next[key])
@@ -77,6 +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?.(next)
80
81
 
81
82
  const pictures = changed.filter(item => item.kind === 'image')
82
83
  await this.queue(pictures, images.concurrency, async item => {
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.0.2",
2
+ "version": "2.0.4",
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
@@ -14,7 +14,11 @@ initial image sizes through the host's `load/geometry.scope.js`. Before reportin
14
14
  an inventory as complete, it verifies that every declared JSON resource and image
15
15
  binary is actually present at the declared version in browser cache. Hosts may use
16
16
  the `Load` component's `onReady` callback to initialize page content only after
17
- that reconciliation has finished. The shared
17
+ the required JSON resources have been reconciled. Image warming continues in
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
+ The shared
18
22
  `Img` component measures its mounted container, treats `src + hash` as binary
19
23
  identity and keeps the decoded displayed image visible until a changed pending
20
24
  binary has decoded and cross-faded.