@hkdigital/lib-core 0.4.71 → 0.4.73

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.
@@ -403,6 +403,19 @@ export default class IndexedDbCache {
403
403
  try {
404
404
  let responseHeaders = new Headers(entry.headers);
405
405
 
406
+ // Calculate actual content length from the body and fix Content-Length header
407
+ const bodySize = responseBody instanceof ArrayBuffer ?
408
+ responseBody.byteLength :
409
+ responseBody instanceof Blob ?
410
+ responseBody.size :
411
+ responseBody.length || 0;
412
+
413
+ // console.debug(`cache-retrieval: fixing content-length from ${responseHeaders.get('content-length')} to ${bodySize}`);
414
+ // console.debug(`cache-retrieval: body type=${typeof responseBody}, constructor=${responseBody?.constructor?.name}, bodySize=${bodySize}`);
415
+
416
+ // Add/fix Content-Length header with actual size
417
+ responseHeaders.set('content-length', bodySize.toString());
418
+
406
419
  // Create Response safely
407
420
  let response;
408
421
  try {
@@ -69,8 +69,34 @@ export default class MemoryResponseCache {
69
69
  // Update last accessed time
70
70
  entry.lastAccessed = Date.now();
71
71
 
72
+ // Get body data safely (works with both real Response and mocks)
73
+ let responseBody;
74
+ try {
75
+ responseBody = await entry.response.arrayBuffer();
76
+ } catch (err) {
77
+ // Fallback for test mocks or consumed responses
78
+ responseBody = entry.response.body || new ArrayBuffer(0);
79
+ }
80
+
81
+ // Calculate size from body data
82
+ const bodySize = responseBody instanceof ArrayBuffer ?
83
+ responseBody.byteLength :
84
+ responseBody instanceof Blob ?
85
+ responseBody.size :
86
+ responseBody.length || 0;
87
+
88
+ // Create new response with corrected Content-Length header
89
+ const fixedHeaders = new Headers(entry.response.headers);
90
+ fixedHeaders.set('content-length', bodySize.toString());
91
+
92
+ const enhancedResponse = new Response(responseBody, {
93
+ status: entry.response.status,
94
+ statusText: entry.response.statusText,
95
+ headers: fixedHeaders
96
+ });
97
+
72
98
  return {
73
- response: entry.response.clone(),
99
+ response: enhancedResponse,
74
100
  metadata: entry.metadata,
75
101
  url: entry.url,
76
102
  timestamp: entry.timestamp,
@@ -387,7 +387,8 @@ export async function httpRequest(options) {
387
387
  if (!isTestEnv) {
388
388
  if (cachedResponse) {
389
389
  console.debug(`http:cache-hit [${url.pathname}]`);
390
- console.debug(`cached-response has body: ${!!cachedResponse.body}`);
390
+ // console.debug(`cached-response has body: ${!!cachedResponse.body}`);
391
+ // console.debug(`cached-response content-length: ${cachedResponse.headers.get('content-length')}`);
391
392
  return cachedResponse;
392
393
  } else {
393
394
  console.debug(`http:cache-miss [${url.pathname}]`);
@@ -245,7 +245,7 @@ export function loadResponseBuffer(response, onProgress) {
245
245
  let bytesLoaded = 0;
246
246
 
247
247
  if (onProgress /*&& size*/) {
248
- console.debug(`loadResponseBuffer:initial-progress size=${size}`);
248
+ // console.debug(`loadResponseBuffer:initial-progress size=${size}`);
249
249
  onProgress({ bytesLoaded, size });
250
250
  }
251
251
 
@@ -275,7 +275,7 @@ export function loadResponseBuffer(response, onProgress) {
275
275
  chunks.push(value);
276
276
 
277
277
  if (onProgress /*&& size*/) {
278
- console.debug(`loadResponseBuffer:chunk-progress ${bytesLoaded}/${size}`);
278
+ // console.debug(`loadResponseBuffer:chunk-progress ${bytesLoaded}/${size}`);
279
279
  onProgress({ bytesLoaded, size });
280
280
  }
281
281
  }
@@ -99,6 +99,8 @@ export default class SceneBase {
99
99
  */
100
100
  constructor() {
101
101
  this.#state.onenter = (currentState) => {
102
+ console.debug('SceneBase:onenter', currentState);
103
+
102
104
  if (currentState === STATE_LOADING) {
103
105
  this.#startLoading();
104
106
  } else if (currentState === STATE_ABORTING) {
@@ -283,6 +285,8 @@ export default class SceneBase {
283
285
  // 0 means no timeout, but actually we use max timeout
284
286
  const waitTimeout = timeoutMs > 0 ? timeoutMs : MAX_TIMEOUT_MS;
285
287
 
288
+ console.debug('SceneBase:waitForState:currentState', this.state);
289
+
286
290
  waitForState(() => {
287
291
  return (
288
292
  this.loaded ||
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hkdigital/lib-core",
3
- "version": "0.4.71",
3
+ "version": "0.4.73",
4
4
  "author": {
5
5
  "name": "HKdigital",
6
6
  "url": "https://hkdigital.nl"