@snowcone-app/ui 0.9.6 → 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 +6 -0
- package/dist/index.cjs +80 -27
- 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 +80 -27
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/composed/HeroProductImage.tsx +39 -4
- package/src/patterns/RealtimeProvider.tsx +71 -31
- package/src/patterns/__tests__/RealtimeProvider.blobLifecycle.test.tsx +214 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
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
|
+
|
|
3
9
|
## 0.9.6
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -6062,6 +6062,7 @@ 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;
|
|
6066
6067
|
var RERENDER_MIN_INTERVAL_MS = 550;
|
|
6067
6068
|
function mergeMockupIds(current, extra) {
|
|
@@ -6206,6 +6207,8 @@ function RealtimeProvider({
|
|
|
6206
6207
|
const configuredMockupIdsRef = (0, import_react25.useRef)([]);
|
|
6207
6208
|
const mockupUrlCacheRef = (0, import_react25.useRef)(/* @__PURE__ */ new Map());
|
|
6208
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());
|
|
6209
6212
|
const pendingPlacementsRef = (0, import_react25.useRef)(/* @__PURE__ */ new Set());
|
|
6210
6213
|
const pendingMockupIdsRef = (0, import_react25.useRef)(/* @__PURE__ */ new Set());
|
|
6211
6214
|
const backgroundsRef = (0, import_react25.useRef)(/* @__PURE__ */ new Map());
|
|
@@ -6232,31 +6235,48 @@ function RealtimeProvider({
|
|
|
6232
6235
|
},
|
|
6233
6236
|
[]
|
|
6234
6237
|
);
|
|
6235
|
-
const
|
|
6236
|
-
|
|
6237
|
-
|
|
6238
|
-
|
|
6239
|
-
|
|
6240
|
-
|
|
6241
|
-
|
|
6242
|
-
|
|
6243
|
-
|
|
6244
|
-
|
|
6245
|
-
|
|
6246
|
-
|
|
6247
|
-
|
|
6248
|
-
|
|
6249
|
-
|
|
6250
|
-
|
|
6251
|
-
|
|
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);
|
|
6252
6260
|
}
|
|
6253
|
-
|
|
6254
|
-
|
|
6255
|
-
}
|
|
6256
|
-
|
|
6261
|
+
blobsByOwnerRef.current.set(owner, list);
|
|
6262
|
+
return url;
|
|
6263
|
+
}
|
|
6264
|
+
if (registeredBlobUrlsRef.current.size >= MAX_CONCURRENT_BLOBS) {
|
|
6265
|
+
const oldest = registeredBlobUrlsRef.current.values().next().value;
|
|
6266
|
+
if (oldest) revokeBlobUrl(oldest);
|
|
6257
6267
|
}
|
|
6268
|
+
registeredBlobUrlsRef.current.add(url);
|
|
6258
6269
|
return url;
|
|
6259
|
-
}, []);
|
|
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]);
|
|
6260
6280
|
const croppedDeliveryEnabled = delivery !== "full-frame";
|
|
6261
6281
|
const sendCropConfig = (0, import_react25.useCallback)(
|
|
6262
6282
|
(withCrop) => {
|
|
@@ -6475,7 +6495,7 @@ function RealtimeProvider({
|
|
|
6475
6495
|
canvas: compositeCanvasRef.current ?? void 0
|
|
6476
6496
|
});
|
|
6477
6497
|
if (gen !== sceneGenRef.current) return;
|
|
6478
|
-
deliverResults([{ ...result, imageUrl: registerBlobUrl(blob) }]);
|
|
6498
|
+
deliverResults([{ ...result, imageUrl: registerBlobUrl(blob, void 0, result.mockupId) }]);
|
|
6479
6499
|
} catch (err) {
|
|
6480
6500
|
if (gen !== sceneGenRef.current || compositeQueueRef.current.has(result.mockupId) || processedFrameRef.current.get(result.mockupId) !== result.imageUrl) {
|
|
6481
6501
|
return;
|
|
@@ -7070,6 +7090,7 @@ function RealtimeProvider({
|
|
|
7070
7090
|
getLatestSentVersions: getLatestSentVersionsStable,
|
|
7071
7091
|
isMockupLoading,
|
|
7072
7092
|
registerBlobUrl,
|
|
7093
|
+
markBlobShown,
|
|
7073
7094
|
// WebRTC streaming
|
|
7074
7095
|
subscribeRTCTiming
|
|
7075
7096
|
}),
|
|
@@ -7102,7 +7123,8 @@ function RealtimeProvider({
|
|
|
7102
7123
|
getCanvasVersion,
|
|
7103
7124
|
getLatestSentVersionsStable,
|
|
7104
7125
|
isMockupLoading,
|
|
7105
|
-
registerBlobUrl
|
|
7126
|
+
registerBlobUrl,
|
|
7127
|
+
markBlobShown
|
|
7106
7128
|
]
|
|
7107
7129
|
);
|
|
7108
7130
|
return /* @__PURE__ */ (0, import_jsx_runtime52.jsx)(RealtimeContext.Provider, { value: contextValue, children });
|
|
@@ -10855,6 +10877,17 @@ var HeroProductImage = (0, import_react46.memo)(function HeroProductImage2({
|
|
|
10855
10877
|
};
|
|
10856
10878
|
}, [mode, realtimeContext?.subscribePendingBlob, placement]);
|
|
10857
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
|
+
}, []);
|
|
10858
10891
|
const renderVersionsRef = (0, import_react46.useRef)(null);
|
|
10859
10892
|
const getLatestSentVersions = realtimeContext?.getLatestSentVersions;
|
|
10860
10893
|
const refusalCodeRef = (0, import_react46.useRef)(null);
|
|
@@ -10878,8 +10911,13 @@ var HeroProductImage = (0, import_react46.memo)(function HeroProductImage2({
|
|
|
10878
10911
|
const behind = versions && sent ? Object.entries(sent).some(([placement2, v]) => (versions[placement2] ?? -1) < v) : rendered < canvas;
|
|
10879
10912
|
node.dataset.canvasVersion = String(canvas);
|
|
10880
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;
|
|
10881
10917
|
node.dataset.renderState = refusalCodeRef.current || behind && sessionErrorCodeRef.current ? "refused" : behind ? "stale" : "current";
|
|
10882
10918
|
}, [getCanvasVersion, getLatestSentVersions]);
|
|
10919
|
+
const applyRenderStampRef = (0, import_react46.useRef)(applyRenderStamp);
|
|
10920
|
+
applyRenderStampRef.current = applyRenderStamp;
|
|
10883
10921
|
(0, import_react46.useEffect)(() => {
|
|
10884
10922
|
applyRenderStamp();
|
|
10885
10923
|
});
|
|
@@ -10889,9 +10927,13 @@ var HeroProductImage = (0, import_react46.memo)(function HeroProductImage2({
|
|
|
10889
10927
|
if (!actualMockupId || !subscribeSent || !subscribeResult) return;
|
|
10890
10928
|
const offSent = subscribeSent(() => applyRenderStamp());
|
|
10891
10929
|
const offResult = subscribeResult(actualMockupId, (result) => {
|
|
10892
|
-
if (typeof result?.requestVersion === "number"
|
|
10893
|
-
|
|
10894
|
-
|
|
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
|
+
}
|
|
10895
10937
|
}
|
|
10896
10938
|
applyRenderStamp();
|
|
10897
10939
|
});
|
|
@@ -11118,8 +11160,13 @@ var HeroProductImage = (0, import_react46.memo)(function HeroProductImage2({
|
|
|
11118
11160
|
};
|
|
11119
11161
|
if (preload.complete) startCrossfade();
|
|
11120
11162
|
else preload.onload = startCrossfade;
|
|
11163
|
+
preload.onerror = () => {
|
|
11164
|
+
frameErrorRef.current = "E_FRAME_UNAVAILABLE";
|
|
11165
|
+
applyRenderStampRef.current?.();
|
|
11166
|
+
};
|
|
11121
11167
|
return () => {
|
|
11122
11168
|
preload.onload = null;
|
|
11169
|
+
preload.onerror = null;
|
|
11123
11170
|
};
|
|
11124
11171
|
}, [displayUrl]);
|
|
11125
11172
|
const handleCrossfadeEnd = (0, import_react46.useCallback)(() => {
|
|
@@ -11199,6 +11246,12 @@ var HeroProductImage = (0, import_react46.memo)(function HeroProductImage2({
|
|
|
11199
11246
|
onLoad: () => {
|
|
11200
11247
|
setImgFailed(false);
|
|
11201
11248
|
setFirstImageLoaded(true);
|
|
11249
|
+
if (renderedUrl) {
|
|
11250
|
+
loadedUrlRef.current = renderedUrl;
|
|
11251
|
+
showVersionOf(renderedUrl);
|
|
11252
|
+
if (actualMockupId) realtimeContext?.markBlobShown?.(actualMockupId, renderedUrl);
|
|
11253
|
+
applyRenderStampRef.current?.();
|
|
11254
|
+
}
|
|
11202
11255
|
if (!onLoadCalledRef.current && onLoad) {
|
|
11203
11256
|
onLoadCalledRef.current = true;
|
|
11204
11257
|
onLoad();
|