@snowcone-app/ui 0.9.6 → 0.9.8
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 +19 -0
- package/dist/index.cjs +109 -28
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +109 -28
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/composed/HeroProductImage.tsx +49 -4
- package/src/patterns/RealtimeProvider.tsx +111 -31
- package/src/patterns/__tests__/RealtimeProvider.blobLifecycle.test.tsx +271 -0
- package/src/patterns/__tests__/RealtimeProvider.cropDelivery.test.tsx +27 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.9.8
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#4403](https://github.com/snowcone-app/snowcone-monorepo/pull/4403) [`9214d20`](https://github.com/snowcone-app/snowcone-monorepo/commit/9214d20624e19ffbb9e2cb9ac4965d9466d06fee) Thanks [@kevinsproles](https://github.com/kevinsproles)! - A composited frame is released only when EVERY element showing that picture has moved past it (`markBlobShown(mockupId, url, consumer)`, `releaseBlobConsumer` on unmount). The phone product page renders each picture twice; releasing on the first element's load revoked the frame its twin was still loading, so the twin kept its old image.
|
|
8
|
+
|
|
9
|
+
- [#4415](https://github.com/snowcone-app/snowcone-monorepo/pull/4415) [`ccc4cf3`](https://github.com/snowcone-app/snowcone-monorepo/commit/ccc4cf371c5f4845e679b8c295e0335881664e96) Thanks [@kevinsproles](https://github.com/kevinsproles)! - The SDK reports `isFrameSuperseded(url)`: true once a newer ws frame for the same mockup has arrived and the old one was revoked. The UI uses it when a cropped frame fails to load: a superseded frame is dropped at once instead of waiting on the 2 s grace, which a 31-picture batch can outlast (React only sees the newer frame with the batch's `all_mockups_rendered`). Before, the grace fired first, cropped delivery went off for the session and a visible picture could stay one version behind.
|
|
10
|
+
|
|
11
|
+
`all_mockups_rendered` now merges its batch into `mockupResults` instead of replacing it. A short batch (a `rerender` answer) landing right after a full one replaced it, React coalesced the two updates, and every other picture kept its previous version.
|
|
12
|
+
|
|
13
|
+
- Updated dependencies [[`ccc4cf3`](https://github.com/snowcone-app/snowcone-monorepo/commit/ccc4cf371c5f4845e679b8c295e0335881664e96)]:
|
|
14
|
+
- @snowcone-app/sdk@0.26.0
|
|
15
|
+
|
|
16
|
+
## 0.9.7
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- [#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"`.
|
|
21
|
+
|
|
3
22
|
## 0.9.6
|
|
4
23
|
|
|
5
24
|
### 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) {
|
|
@@ -6180,8 +6181,11 @@ function RealtimeProvider({
|
|
|
6180
6181
|
hasPendingBlobs,
|
|
6181
6182
|
getLastSentVersion,
|
|
6182
6183
|
getLatestSentVersions,
|
|
6183
|
-
rerender: rerenderRaw
|
|
6184
|
+
rerender: rerenderRaw,
|
|
6185
|
+
isFrameSuperseded
|
|
6184
6186
|
} = realtimeMockup;
|
|
6187
|
+
const isFrameSupersededRef = (0, import_react25.useRef)(isFrameSuperseded);
|
|
6188
|
+
isFrameSupersededRef.current = isFrameSuperseded;
|
|
6185
6189
|
const mockupResultsRef = (0, import_react25.useRef)([]);
|
|
6186
6190
|
const mockupSubscribersRef = (0, import_react25.useRef)(
|
|
6187
6191
|
/* @__PURE__ */ new Set()
|
|
@@ -6206,6 +6210,8 @@ function RealtimeProvider({
|
|
|
6206
6210
|
const configuredMockupIdsRef = (0, import_react25.useRef)([]);
|
|
6207
6211
|
const mockupUrlCacheRef = (0, import_react25.useRef)(/* @__PURE__ */ new Map());
|
|
6208
6212
|
const registeredBlobUrlsRef = (0, import_react25.useRef)(/* @__PURE__ */ new Set());
|
|
6213
|
+
const blobsByOwnerRef = (0, import_react25.useRef)(/* @__PURE__ */ new Map());
|
|
6214
|
+
const shownBlobByOwnerRef = (0, import_react25.useRef)(/* @__PURE__ */ new Map());
|
|
6209
6215
|
const pendingPlacementsRef = (0, import_react25.useRef)(/* @__PURE__ */ new Set());
|
|
6210
6216
|
const pendingMockupIdsRef = (0, import_react25.useRef)(/* @__PURE__ */ new Set());
|
|
6211
6217
|
const backgroundsRef = (0, import_react25.useRef)(/* @__PURE__ */ new Map());
|
|
@@ -6232,31 +6238,61 @@ function RealtimeProvider({
|
|
|
6232
6238
|
},
|
|
6233
6239
|
[]
|
|
6234
6240
|
);
|
|
6235
|
-
const
|
|
6236
|
-
|
|
6237
|
-
|
|
6238
|
-
|
|
6239
|
-
|
|
6240
|
-
|
|
6241
|
-
|
|
6242
|
-
|
|
6243
|
-
|
|
6244
|
-
|
|
6245
|
-
|
|
6246
|
-
|
|
6247
|
-
|
|
6248
|
-
|
|
6249
|
-
|
|
6250
|
-
|
|
6251
|
-
|
|
6241
|
+
const revokeBlobUrl = (0, import_react25.useCallback)((url) => {
|
|
6242
|
+
URL.revokeObjectURL(url);
|
|
6243
|
+
registeredBlobUrlsRef.current.delete(url);
|
|
6244
|
+
mockupUrlCacheRef.current.forEach((value, key) => {
|
|
6245
|
+
if (value.url === url) mockupUrlCacheRef.current.delete(key);
|
|
6246
|
+
});
|
|
6247
|
+
mockupResultsRef.current = mockupResultsRef.current.filter((r) => r.imageUrl !== url);
|
|
6248
|
+
}, []);
|
|
6249
|
+
const registerBlobUrl = (0, import_react25.useCallback)((blobOrUrl, _placementName, owner) => {
|
|
6250
|
+
if (!(blobOrUrl instanceof Blob)) return blobOrUrl;
|
|
6251
|
+
const url = URL.createObjectURL(blobOrUrl);
|
|
6252
|
+
if (owner) {
|
|
6253
|
+
const list = [url, ...blobsByOwnerRef.current.get(owner) ?? []];
|
|
6254
|
+
const shown = new Set(shownBlobByOwnerRef.current.get(owner)?.values() ?? []);
|
|
6255
|
+
while (list.length > MAX_FRAMES_PER_PICTURE) {
|
|
6256
|
+
const victimIdx = [...list.keys()].reverse().find((i) => i > 0 && !shown.has(list[i]));
|
|
6257
|
+
if (victimIdx === void 0) break;
|
|
6258
|
+
const [victim] = list.splice(victimIdx, 1);
|
|
6259
|
+
console.error(
|
|
6260
|
+
`[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).`
|
|
6261
|
+
);
|
|
6262
|
+
revokeBlobUrl(victim);
|
|
6252
6263
|
}
|
|
6253
|
-
|
|
6254
|
-
|
|
6255
|
-
}
|
|
6256
|
-
|
|
6264
|
+
blobsByOwnerRef.current.set(owner, list);
|
|
6265
|
+
return url;
|
|
6266
|
+
}
|
|
6267
|
+
if (registeredBlobUrlsRef.current.size >= MAX_CONCURRENT_BLOBS) {
|
|
6268
|
+
const oldest = registeredBlobUrlsRef.current.values().next().value;
|
|
6269
|
+
if (oldest) revokeBlobUrl(oldest);
|
|
6257
6270
|
}
|
|
6271
|
+
registeredBlobUrlsRef.current.add(url);
|
|
6258
6272
|
return url;
|
|
6259
|
-
}, []);
|
|
6273
|
+
}, [revokeBlobUrl]);
|
|
6274
|
+
const releaseOlderFrames = (0, import_react25.useCallback)((owner) => {
|
|
6275
|
+
const list = blobsByOwnerRef.current.get(owner);
|
|
6276
|
+
const shown = shownBlobByOwnerRef.current.get(owner);
|
|
6277
|
+
if (!list || !shown || shown.size === 0) return;
|
|
6278
|
+
const oldestShownIdx = Math.max(...[...shown.values()].map((u) => list.indexOf(u)));
|
|
6279
|
+
if (oldestShownIdx < 0) return;
|
|
6280
|
+
list.slice(oldestShownIdx + 1).forEach(revokeBlobUrl);
|
|
6281
|
+
blobsByOwnerRef.current.set(owner, list.slice(0, oldestShownIdx + 1));
|
|
6282
|
+
}, [revokeBlobUrl]);
|
|
6283
|
+
const markBlobShown = (0, import_react25.useCallback)((owner, url, consumer = "default") => {
|
|
6284
|
+
const list = blobsByOwnerRef.current.get(owner);
|
|
6285
|
+
if (!list || list.indexOf(url) < 0) return;
|
|
6286
|
+
const shown = shownBlobByOwnerRef.current.get(owner) ?? /* @__PURE__ */ new Map();
|
|
6287
|
+
shown.set(consumer, url);
|
|
6288
|
+
shownBlobByOwnerRef.current.set(owner, shown);
|
|
6289
|
+
releaseOlderFrames(owner);
|
|
6290
|
+
}, [releaseOlderFrames]);
|
|
6291
|
+
const releaseBlobConsumer = (0, import_react25.useCallback)((owner, consumer) => {
|
|
6292
|
+
const shown = shownBlobByOwnerRef.current.get(owner);
|
|
6293
|
+
if (!shown?.delete(consumer)) return;
|
|
6294
|
+
releaseOlderFrames(owner);
|
|
6295
|
+
}, [releaseOlderFrames]);
|
|
6260
6296
|
const croppedDeliveryEnabled = delivery !== "full-frame";
|
|
6261
6297
|
const sendCropConfig = (0, import_react25.useCallback)(
|
|
6262
6298
|
(withCrop) => {
|
|
@@ -6475,11 +6511,12 @@ function RealtimeProvider({
|
|
|
6475
6511
|
canvas: compositeCanvasRef.current ?? void 0
|
|
6476
6512
|
});
|
|
6477
6513
|
if (gen !== sceneGenRef.current) return;
|
|
6478
|
-
deliverResults([{ ...result, imageUrl: registerBlobUrl(blob) }]);
|
|
6514
|
+
deliverResults([{ ...result, imageUrl: registerBlobUrl(blob, void 0, result.mockupId) }]);
|
|
6479
6515
|
} catch (err) {
|
|
6480
6516
|
if (gen !== sceneGenRef.current || compositeQueueRef.current.has(result.mockupId) || processedFrameRef.current.get(result.mockupId) !== result.imageUrl) {
|
|
6481
6517
|
return;
|
|
6482
6518
|
}
|
|
6519
|
+
if (isFrameSupersededRef.current?.(result.imageUrl)) return;
|
|
6483
6520
|
const message = err instanceof Error ? err.message : String(err);
|
|
6484
6521
|
if (result.imageUrl.startsWith("blob:") && message.startsWith("E_OVERLAY_FRAME_LOAD") && message.includes(result.imageUrl.slice(0, 160))) {
|
|
6485
6522
|
const failedUrl = result.imageUrl;
|
|
@@ -7070,6 +7107,8 @@ function RealtimeProvider({
|
|
|
7070
7107
|
getLatestSentVersions: getLatestSentVersionsStable,
|
|
7071
7108
|
isMockupLoading,
|
|
7072
7109
|
registerBlobUrl,
|
|
7110
|
+
markBlobShown,
|
|
7111
|
+
releaseBlobConsumer,
|
|
7073
7112
|
// WebRTC streaming
|
|
7074
7113
|
subscribeRTCTiming
|
|
7075
7114
|
}),
|
|
@@ -7102,7 +7141,9 @@ function RealtimeProvider({
|
|
|
7102
7141
|
getCanvasVersion,
|
|
7103
7142
|
getLatestSentVersionsStable,
|
|
7104
7143
|
isMockupLoading,
|
|
7105
|
-
registerBlobUrl
|
|
7144
|
+
registerBlobUrl,
|
|
7145
|
+
markBlobShown,
|
|
7146
|
+
releaseBlobConsumer
|
|
7106
7147
|
]
|
|
7107
7148
|
);
|
|
7108
7149
|
return /* @__PURE__ */ (0, import_jsx_runtime52.jsx)(RealtimeContext.Provider, { value: contextValue, children });
|
|
@@ -10855,6 +10896,26 @@ var HeroProductImage = (0, import_react46.memo)(function HeroProductImage2({
|
|
|
10855
10896
|
};
|
|
10856
10897
|
}, [mode, realtimeContext?.subscribePendingBlob, placement]);
|
|
10857
10898
|
const renderVersionRef = (0, import_react46.useRef)(0);
|
|
10899
|
+
const arrivedVersionRef = (0, import_react46.useRef)(0);
|
|
10900
|
+
const versionByUrlRef = (0, import_react46.useRef)(/* @__PURE__ */ new Map());
|
|
10901
|
+
const loadedUrlRef = (0, import_react46.useRef)(null);
|
|
10902
|
+
const blobConsumerRef = (0, import_react46.useRef)(`el-${Math.random().toString(36).slice(2, 10)}`);
|
|
10903
|
+
const releaseBlobConsumer = realtimeContext?.releaseBlobConsumer;
|
|
10904
|
+
(0, import_react46.useEffect)(() => {
|
|
10905
|
+
const id = actualMockupId;
|
|
10906
|
+
const consumer = blobConsumerRef.current;
|
|
10907
|
+
return () => {
|
|
10908
|
+
if (id) releaseBlobConsumer?.(id, consumer);
|
|
10909
|
+
};
|
|
10910
|
+
}, [actualMockupId, releaseBlobConsumer]);
|
|
10911
|
+
const frameErrorRef = (0, import_react46.useRef)(null);
|
|
10912
|
+
const showVersionOf = (0, import_react46.useCallback)((url) => {
|
|
10913
|
+
const e = versionByUrlRef.current.get(url);
|
|
10914
|
+
if (!e || e.v < renderVersionRef.current) return;
|
|
10915
|
+
renderVersionRef.current = e.v;
|
|
10916
|
+
renderVersionsRef.current = e.versions;
|
|
10917
|
+
frameErrorRef.current = null;
|
|
10918
|
+
}, []);
|
|
10858
10919
|
const renderVersionsRef = (0, import_react46.useRef)(null);
|
|
10859
10920
|
const getLatestSentVersions = realtimeContext?.getLatestSentVersions;
|
|
10860
10921
|
const refusalCodeRef = (0, import_react46.useRef)(null);
|
|
@@ -10878,8 +10939,13 @@ var HeroProductImage = (0, import_react46.memo)(function HeroProductImage2({
|
|
|
10878
10939
|
const behind = versions && sent ? Object.entries(sent).some(([placement2, v]) => (versions[placement2] ?? -1) < v) : rendered < canvas;
|
|
10879
10940
|
node.dataset.canvasVersion = String(canvas);
|
|
10880
10941
|
node.dataset.renderVersion = String(rendered);
|
|
10942
|
+
node.dataset.arrivedVersion = String(arrivedVersionRef.current);
|
|
10943
|
+
if (frameErrorRef.current) node.dataset.frameError = frameErrorRef.current;
|
|
10944
|
+
else delete node.dataset.frameError;
|
|
10881
10945
|
node.dataset.renderState = refusalCodeRef.current || behind && sessionErrorCodeRef.current ? "refused" : behind ? "stale" : "current";
|
|
10882
10946
|
}, [getCanvasVersion, getLatestSentVersions]);
|
|
10947
|
+
const applyRenderStampRef = (0, import_react46.useRef)(applyRenderStamp);
|
|
10948
|
+
applyRenderStampRef.current = applyRenderStamp;
|
|
10883
10949
|
(0, import_react46.useEffect)(() => {
|
|
10884
10950
|
applyRenderStamp();
|
|
10885
10951
|
});
|
|
@@ -10889,9 +10955,13 @@ var HeroProductImage = (0, import_react46.memo)(function HeroProductImage2({
|
|
|
10889
10955
|
if (!actualMockupId || !subscribeSent || !subscribeResult) return;
|
|
10890
10956
|
const offSent = subscribeSent(() => applyRenderStamp());
|
|
10891
10957
|
const offResult = subscribeResult(actualMockupId, (result) => {
|
|
10892
|
-
if (typeof result?.requestVersion === "number"
|
|
10893
|
-
|
|
10894
|
-
|
|
10958
|
+
if (typeof result?.requestVersion === "number") {
|
|
10959
|
+
arrivedVersionRef.current = Math.max(arrivedVersionRef.current, result.requestVersion);
|
|
10960
|
+
const url = realtimeContext?.getMockupUrl?.(result.mockupId) ?? result.imageUrl;
|
|
10961
|
+
if (url) {
|
|
10962
|
+
versionByUrlRef.current.set(url, { v: result.requestVersion, versions: result.versions ?? null });
|
|
10963
|
+
if (url === loadedUrlRef.current) showVersionOf(url);
|
|
10964
|
+
}
|
|
10895
10965
|
}
|
|
10896
10966
|
applyRenderStamp();
|
|
10897
10967
|
});
|
|
@@ -11118,8 +11188,13 @@ var HeroProductImage = (0, import_react46.memo)(function HeroProductImage2({
|
|
|
11118
11188
|
};
|
|
11119
11189
|
if (preload.complete) startCrossfade();
|
|
11120
11190
|
else preload.onload = startCrossfade;
|
|
11191
|
+
preload.onerror = () => {
|
|
11192
|
+
frameErrorRef.current = "E_FRAME_UNAVAILABLE";
|
|
11193
|
+
applyRenderStampRef.current?.();
|
|
11194
|
+
};
|
|
11121
11195
|
return () => {
|
|
11122
11196
|
preload.onload = null;
|
|
11197
|
+
preload.onerror = null;
|
|
11123
11198
|
};
|
|
11124
11199
|
}, [displayUrl]);
|
|
11125
11200
|
const handleCrossfadeEnd = (0, import_react46.useCallback)(() => {
|
|
@@ -11199,6 +11274,12 @@ var HeroProductImage = (0, import_react46.memo)(function HeroProductImage2({
|
|
|
11199
11274
|
onLoad: () => {
|
|
11200
11275
|
setImgFailed(false);
|
|
11201
11276
|
setFirstImageLoaded(true);
|
|
11277
|
+
if (renderedUrl) {
|
|
11278
|
+
loadedUrlRef.current = renderedUrl;
|
|
11279
|
+
showVersionOf(renderedUrl);
|
|
11280
|
+
if (actualMockupId) realtimeContext?.markBlobShown?.(actualMockupId, renderedUrl, blobConsumerRef.current);
|
|
11281
|
+
applyRenderStampRef.current?.();
|
|
11282
|
+
}
|
|
11202
11283
|
if (!onLoadCalledRef.current && onLoad) {
|
|
11203
11284
|
onLoadCalledRef.current = true;
|
|
11204
11285
|
onLoad();
|