@snowcone-app/ui 0.9.5 → 0.9.7
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/CHANGELOG.md +12 -0
- package/dist/index.cjs +109 -31
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +109 -31
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/composed/HeroProductImage.tsx +39 -4
- package/src/patterns/RealtimeProvider.tsx +109 -35
- package/src/patterns/__tests__/RealtimeProvider.blobLifecycle.test.tsx +214 -0
- package/src/patterns/__tests__/RealtimeProvider.cropDelivery.test.tsx +24 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.9.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#4390](https://github.com/snowcone-app/snowcone-monorepo/pull/4390) [`6ca6571`](https://github.com/snowcone-app/snowcone-monorepo/commit/6ca65710960def1c90b3e3d32cc52f899ddb3ba1) Thanks [@kevinsproles](https://github.com/kevinsproles)! - Live pictures always show the frame they say they show. Composited frames are now released per picture, only once that picture has shown a newer one (`markBlobShown`, from its image load), instead of a global "newest 5" that revoked other pictures' fresh frames before they loaded (31 pictures per edit: the picture kept its old image). At most 3 live frames per picture (a typed `E_BLOB_PICTURE_BOUND` beyond that, dropping only a never-shown frame). `HeroProductImage`'s `data-render-version` is the version of the image ON SCREEN (stamped on its load); `data-arrived-version` is what has arrived; a frame that cannot load keeps the old image and sets `data-frame-error="E_FRAME_UNAVAILABLE"`.
|
|
8
|
+
|
|
9
|
+
## 0.9.6
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#4354](https://github.com/snowcone-app/snowcone-monorepo/pull/4354) [`426ba73`](https://github.com/snowcone-app/snowcone-monorepo/commit/426ba73e27630f48c0c673a9f3510bc0c14540ab) Thanks [@kevinsproles](https://github.com/kevinsproles)! - `rerender` requests are paced to the render box's limit (one per 550 ms): failures inside the interval wait and go out as one request, instead of being refused with E_RERENDER_RATE_LIMITED and falling back to configs.
|
|
14
|
+
|
|
3
15
|
## 0.9.5
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -6062,7 +6062,9 @@ async function compositeCroppedFrame(args) {
|
|
|
6062
6062
|
var import_jsx_runtime52 = require("react/jsx-runtime");
|
|
6063
6063
|
var DEFAULT_ARTBOARD_SIZE = 2e3;
|
|
6064
6064
|
var MAX_CONCURRENT_BLOBS = 5;
|
|
6065
|
+
var MAX_FRAMES_PER_PICTURE = 3;
|
|
6065
6066
|
var FRAME_SUPERSEDE_GRACE_MS = 2e3;
|
|
6067
|
+
var RERENDER_MIN_INTERVAL_MS = 550;
|
|
6066
6068
|
function mergeMockupIds(current, extra) {
|
|
6067
6069
|
const out = [...current];
|
|
6068
6070
|
for (const id of extra) if (!out.includes(id)) out.push(id);
|
|
@@ -6205,6 +6207,8 @@ function RealtimeProvider({
|
|
|
6205
6207
|
const configuredMockupIdsRef = (0, import_react25.useRef)([]);
|
|
6206
6208
|
const mockupUrlCacheRef = (0, import_react25.useRef)(/* @__PURE__ */ new Map());
|
|
6207
6209
|
const registeredBlobUrlsRef = (0, import_react25.useRef)(/* @__PURE__ */ new Set());
|
|
6210
|
+
const blobsByOwnerRef = (0, import_react25.useRef)(/* @__PURE__ */ new Map());
|
|
6211
|
+
const shownBlobByOwnerRef = (0, import_react25.useRef)(/* @__PURE__ */ new Map());
|
|
6208
6212
|
const pendingPlacementsRef = (0, import_react25.useRef)(/* @__PURE__ */ new Set());
|
|
6209
6213
|
const pendingMockupIdsRef = (0, import_react25.useRef)(/* @__PURE__ */ new Set());
|
|
6210
6214
|
const backgroundsRef = (0, import_react25.useRef)(/* @__PURE__ */ new Map());
|
|
@@ -6220,6 +6224,9 @@ function RealtimeProvider({
|
|
|
6220
6224
|
const serverStampsVersionsRef = (0, import_react25.useRef)(false);
|
|
6221
6225
|
const pendingRerenderRef = (0, import_react25.useRef)([]);
|
|
6222
6226
|
const forceRerenderByConfigRef = (0, import_react25.useRef)(null);
|
|
6227
|
+
const lastRerenderAtRef = (0, import_react25.useRef)(0);
|
|
6228
|
+
const rerenderQueueRef = (0, import_react25.useRef)([]);
|
|
6229
|
+
const rerenderTimerRef = (0, import_react25.useRef)(null);
|
|
6223
6230
|
const fullFrameRerenderIdsRef = (0, import_react25.useRef)(/* @__PURE__ */ new Set());
|
|
6224
6231
|
const fullFrameRerenderTimerRef = (0, import_react25.useRef)(null);
|
|
6225
6232
|
(0, import_react25.useEffect)(
|
|
@@ -6228,31 +6235,48 @@ function RealtimeProvider({
|
|
|
6228
6235
|
},
|
|
6229
6236
|
[]
|
|
6230
6237
|
);
|
|
6231
|
-
const
|
|
6232
|
-
|
|
6233
|
-
|
|
6234
|
-
|
|
6235
|
-
|
|
6236
|
-
|
|
6237
|
-
|
|
6238
|
-
|
|
6239
|
-
|
|
6240
|
-
|
|
6241
|
-
|
|
6242
|
-
|
|
6243
|
-
|
|
6244
|
-
|
|
6245
|
-
|
|
6246
|
-
|
|
6247
|
-
|
|
6238
|
+
const revokeBlobUrl = (0, import_react25.useCallback)((url) => {
|
|
6239
|
+
URL.revokeObjectURL(url);
|
|
6240
|
+
registeredBlobUrlsRef.current.delete(url);
|
|
6241
|
+
mockupUrlCacheRef.current.forEach((value, key) => {
|
|
6242
|
+
if (value.url === url) mockupUrlCacheRef.current.delete(key);
|
|
6243
|
+
});
|
|
6244
|
+
mockupResultsRef.current = mockupResultsRef.current.filter((r) => r.imageUrl !== url);
|
|
6245
|
+
}, []);
|
|
6246
|
+
const registerBlobUrl = (0, import_react25.useCallback)((blobOrUrl, _placementName, owner) => {
|
|
6247
|
+
if (!(blobOrUrl instanceof Blob)) return blobOrUrl;
|
|
6248
|
+
const url = URL.createObjectURL(blobOrUrl);
|
|
6249
|
+
if (owner) {
|
|
6250
|
+
const list = [url, ...blobsByOwnerRef.current.get(owner) ?? []];
|
|
6251
|
+
const shown = shownBlobByOwnerRef.current.get(owner);
|
|
6252
|
+
while (list.length > MAX_FRAMES_PER_PICTURE) {
|
|
6253
|
+
const victimIdx = [...list.keys()].reverse().find((i) => i > 0 && list[i] !== shown);
|
|
6254
|
+
if (victimIdx === void 0) break;
|
|
6255
|
+
const [victim] = list.splice(victimIdx, 1);
|
|
6256
|
+
console.error(
|
|
6257
|
+
`[RealtimeProvider] E_BLOB_PICTURE_BOUND: ${owner} has more than ${MAX_FRAMES_PER_PICTURE} frames waiting to be shown; dropping its oldest unshown frame (the picture on screen is kept).`
|
|
6258
|
+
);
|
|
6259
|
+
revokeBlobUrl(victim);
|
|
6248
6260
|
}
|
|
6249
|
-
|
|
6250
|
-
|
|
6251
|
-
} else {
|
|
6252
|
-
url = blobOrUrl;
|
|
6261
|
+
blobsByOwnerRef.current.set(owner, list);
|
|
6262
|
+
return url;
|
|
6253
6263
|
}
|
|
6264
|
+
if (registeredBlobUrlsRef.current.size >= MAX_CONCURRENT_BLOBS) {
|
|
6265
|
+
const oldest = registeredBlobUrlsRef.current.values().next().value;
|
|
6266
|
+
if (oldest) revokeBlobUrl(oldest);
|
|
6267
|
+
}
|
|
6268
|
+
registeredBlobUrlsRef.current.add(url);
|
|
6254
6269
|
return url;
|
|
6255
|
-
}, []);
|
|
6270
|
+
}, [revokeBlobUrl]);
|
|
6271
|
+
const markBlobShown = (0, import_react25.useCallback)((owner, url) => {
|
|
6272
|
+
const list = blobsByOwnerRef.current.get(owner);
|
|
6273
|
+
if (!list) return;
|
|
6274
|
+
const idx = list.indexOf(url);
|
|
6275
|
+
if (idx < 0) return;
|
|
6276
|
+
shownBlobByOwnerRef.current.set(owner, url);
|
|
6277
|
+
list.slice(idx + 1).forEach(revokeBlobUrl);
|
|
6278
|
+
blobsByOwnerRef.current.set(owner, list.slice(0, idx + 1));
|
|
6279
|
+
}, [revokeBlobUrl]);
|
|
6256
6280
|
const croppedDeliveryEnabled = delivery !== "full-frame";
|
|
6257
6281
|
const sendCropConfig = (0, import_react25.useCallback)(
|
|
6258
6282
|
(withCrop) => {
|
|
@@ -6302,6 +6326,28 @@ function RealtimeProvider({
|
|
|
6302
6326
|
[sendFullFrameConfig]
|
|
6303
6327
|
);
|
|
6304
6328
|
forceRerenderByConfigRef.current = forceRerenderByConfig;
|
|
6329
|
+
const sendRerenderPaced = (0, import_react25.useCallback)(
|
|
6330
|
+
(ids) => {
|
|
6331
|
+
rerenderQueueRef.current = mergeMockupIds(rerenderQueueRef.current, ids);
|
|
6332
|
+
if (rerenderTimerRef.current) return;
|
|
6333
|
+
const wait = Math.max(0, lastRerenderAtRef.current + RERENDER_MIN_INTERVAL_MS - Date.now());
|
|
6334
|
+
const flush = () => {
|
|
6335
|
+
rerenderTimerRef.current = null;
|
|
6336
|
+
const batch = rerenderQueueRef.current;
|
|
6337
|
+
rerenderQueueRef.current = [];
|
|
6338
|
+
if (batch.length === 0) return;
|
|
6339
|
+
lastRerenderAtRef.current = Date.now();
|
|
6340
|
+
pendingRerenderRef.current = mergeMockupIds(pendingRerenderRef.current, batch);
|
|
6341
|
+
if (!rerenderRaw(batch)) {
|
|
6342
|
+
pendingRerenderRef.current = [];
|
|
6343
|
+
forceRerenderByConfigRef.current?.(batch);
|
|
6344
|
+
}
|
|
6345
|
+
};
|
|
6346
|
+
if (wait === 0) flush();
|
|
6347
|
+
else rerenderTimerRef.current = setTimeout(flush, wait);
|
|
6348
|
+
},
|
|
6349
|
+
[rerenderRaw]
|
|
6350
|
+
);
|
|
6305
6351
|
const rerenderFullFrame = (0, import_react25.useCallback)(
|
|
6306
6352
|
(mockupId) => {
|
|
6307
6353
|
fullFrameRerenderIdsRef.current.add(mockupId);
|
|
@@ -6322,14 +6368,13 @@ function RealtimeProvider({
|
|
|
6322
6368
|
}
|
|
6323
6369
|
if (serverStampsVersionsRef.current) {
|
|
6324
6370
|
sendFullFrameConfig(ids);
|
|
6325
|
-
|
|
6326
|
-
|
|
6327
|
-
pendingRerenderRef.current = [];
|
|
6371
|
+
sendRerenderPaced(failed);
|
|
6372
|
+
return;
|
|
6328
6373
|
}
|
|
6329
6374
|
forceRerenderByConfig(failed);
|
|
6330
6375
|
}, 0);
|
|
6331
6376
|
},
|
|
6332
|
-
[sendFullFrameConfig, forceRerenderByConfig,
|
|
6377
|
+
[sendFullFrameConfig, forceRerenderByConfig, sendRerenderPaced]
|
|
6333
6378
|
);
|
|
6334
6379
|
const maybeFlipCrop = (0, import_react25.useCallback)(() => {
|
|
6335
6380
|
if (!croppedDeliveryEnabled || !cropCapableRef.current) return;
|
|
@@ -6450,7 +6495,7 @@ function RealtimeProvider({
|
|
|
6450
6495
|
canvas: compositeCanvasRef.current ?? void 0
|
|
6451
6496
|
});
|
|
6452
6497
|
if (gen !== sceneGenRef.current) return;
|
|
6453
|
-
deliverResults([{ ...result, imageUrl: registerBlobUrl(blob) }]);
|
|
6498
|
+
deliverResults([{ ...result, imageUrl: registerBlobUrl(blob, void 0, result.mockupId) }]);
|
|
6454
6499
|
} catch (err) {
|
|
6455
6500
|
if (gen !== sceneGenRef.current || compositeQueueRef.current.has(result.mockupId) || processedFrameRef.current.get(result.mockupId) !== result.imageUrl) {
|
|
6456
6501
|
return;
|
|
@@ -7045,6 +7090,7 @@ function RealtimeProvider({
|
|
|
7045
7090
|
getLatestSentVersions: getLatestSentVersionsStable,
|
|
7046
7091
|
isMockupLoading,
|
|
7047
7092
|
registerBlobUrl,
|
|
7093
|
+
markBlobShown,
|
|
7048
7094
|
// WebRTC streaming
|
|
7049
7095
|
subscribeRTCTiming
|
|
7050
7096
|
}),
|
|
@@ -7077,7 +7123,8 @@ function RealtimeProvider({
|
|
|
7077
7123
|
getCanvasVersion,
|
|
7078
7124
|
getLatestSentVersionsStable,
|
|
7079
7125
|
isMockupLoading,
|
|
7080
|
-
registerBlobUrl
|
|
7126
|
+
registerBlobUrl,
|
|
7127
|
+
markBlobShown
|
|
7081
7128
|
]
|
|
7082
7129
|
);
|
|
7083
7130
|
return /* @__PURE__ */ (0, import_jsx_runtime52.jsx)(RealtimeContext.Provider, { value: contextValue, children });
|
|
@@ -10830,6 +10877,17 @@ var HeroProductImage = (0, import_react46.memo)(function HeroProductImage2({
|
|
|
10830
10877
|
};
|
|
10831
10878
|
}, [mode, realtimeContext?.subscribePendingBlob, placement]);
|
|
10832
10879
|
const renderVersionRef = (0, import_react46.useRef)(0);
|
|
10880
|
+
const arrivedVersionRef = (0, import_react46.useRef)(0);
|
|
10881
|
+
const versionByUrlRef = (0, import_react46.useRef)(/* @__PURE__ */ new Map());
|
|
10882
|
+
const loadedUrlRef = (0, import_react46.useRef)(null);
|
|
10883
|
+
const frameErrorRef = (0, import_react46.useRef)(null);
|
|
10884
|
+
const showVersionOf = (0, import_react46.useCallback)((url) => {
|
|
10885
|
+
const e = versionByUrlRef.current.get(url);
|
|
10886
|
+
if (!e || e.v < renderVersionRef.current) return;
|
|
10887
|
+
renderVersionRef.current = e.v;
|
|
10888
|
+
renderVersionsRef.current = e.versions;
|
|
10889
|
+
frameErrorRef.current = null;
|
|
10890
|
+
}, []);
|
|
10833
10891
|
const renderVersionsRef = (0, import_react46.useRef)(null);
|
|
10834
10892
|
const getLatestSentVersions = realtimeContext?.getLatestSentVersions;
|
|
10835
10893
|
const refusalCodeRef = (0, import_react46.useRef)(null);
|
|
@@ -10853,8 +10911,13 @@ var HeroProductImage = (0, import_react46.memo)(function HeroProductImage2({
|
|
|
10853
10911
|
const behind = versions && sent ? Object.entries(sent).some(([placement2, v]) => (versions[placement2] ?? -1) < v) : rendered < canvas;
|
|
10854
10912
|
node.dataset.canvasVersion = String(canvas);
|
|
10855
10913
|
node.dataset.renderVersion = String(rendered);
|
|
10914
|
+
node.dataset.arrivedVersion = String(arrivedVersionRef.current);
|
|
10915
|
+
if (frameErrorRef.current) node.dataset.frameError = frameErrorRef.current;
|
|
10916
|
+
else delete node.dataset.frameError;
|
|
10856
10917
|
node.dataset.renderState = refusalCodeRef.current || behind && sessionErrorCodeRef.current ? "refused" : behind ? "stale" : "current";
|
|
10857
10918
|
}, [getCanvasVersion, getLatestSentVersions]);
|
|
10919
|
+
const applyRenderStampRef = (0, import_react46.useRef)(applyRenderStamp);
|
|
10920
|
+
applyRenderStampRef.current = applyRenderStamp;
|
|
10858
10921
|
(0, import_react46.useEffect)(() => {
|
|
10859
10922
|
applyRenderStamp();
|
|
10860
10923
|
});
|
|
@@ -10864,9 +10927,13 @@ var HeroProductImage = (0, import_react46.memo)(function HeroProductImage2({
|
|
|
10864
10927
|
if (!actualMockupId || !subscribeSent || !subscribeResult) return;
|
|
10865
10928
|
const offSent = subscribeSent(() => applyRenderStamp());
|
|
10866
10929
|
const offResult = subscribeResult(actualMockupId, (result) => {
|
|
10867
|
-
if (typeof result?.requestVersion === "number"
|
|
10868
|
-
|
|
10869
|
-
|
|
10930
|
+
if (typeof result?.requestVersion === "number") {
|
|
10931
|
+
arrivedVersionRef.current = Math.max(arrivedVersionRef.current, result.requestVersion);
|
|
10932
|
+
const url = realtimeContext?.getMockupUrl?.(result.mockupId) ?? result.imageUrl;
|
|
10933
|
+
if (url) {
|
|
10934
|
+
versionByUrlRef.current.set(url, { v: result.requestVersion, versions: result.versions ?? null });
|
|
10935
|
+
if (url === loadedUrlRef.current) showVersionOf(url);
|
|
10936
|
+
}
|
|
10870
10937
|
}
|
|
10871
10938
|
applyRenderStamp();
|
|
10872
10939
|
});
|
|
@@ -11093,8 +11160,13 @@ var HeroProductImage = (0, import_react46.memo)(function HeroProductImage2({
|
|
|
11093
11160
|
};
|
|
11094
11161
|
if (preload.complete) startCrossfade();
|
|
11095
11162
|
else preload.onload = startCrossfade;
|
|
11163
|
+
preload.onerror = () => {
|
|
11164
|
+
frameErrorRef.current = "E_FRAME_UNAVAILABLE";
|
|
11165
|
+
applyRenderStampRef.current?.();
|
|
11166
|
+
};
|
|
11096
11167
|
return () => {
|
|
11097
11168
|
preload.onload = null;
|
|
11169
|
+
preload.onerror = null;
|
|
11098
11170
|
};
|
|
11099
11171
|
}, [displayUrl]);
|
|
11100
11172
|
const handleCrossfadeEnd = (0, import_react46.useCallback)(() => {
|
|
@@ -11174,6 +11246,12 @@ var HeroProductImage = (0, import_react46.memo)(function HeroProductImage2({
|
|
|
11174
11246
|
onLoad: () => {
|
|
11175
11247
|
setImgFailed(false);
|
|
11176
11248
|
setFirstImageLoaded(true);
|
|
11249
|
+
if (renderedUrl) {
|
|
11250
|
+
loadedUrlRef.current = renderedUrl;
|
|
11251
|
+
showVersionOf(renderedUrl);
|
|
11252
|
+
if (actualMockupId) realtimeContext?.markBlobShown?.(actualMockupId, renderedUrl);
|
|
11253
|
+
applyRenderStampRef.current?.();
|
|
11254
|
+
}
|
|
11177
11255
|
if (!onLoadCalledRef.current && onLoad) {
|
|
11178
11256
|
onLoadCalledRef.current = true;
|
|
11179
11257
|
onLoad();
|