@snowcone-app/ui 0.10.0 → 0.10.1
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 +14 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +14 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/patterns/RealtimeProvider.tsx +23 -4
- package/src/patterns/__tests__/RealtimeProvider.sessionShape.test.tsx +36 -0
package/package.json
CHANGED
|
@@ -75,6 +75,8 @@ const FRAME_SUPERSEDE_GRACE_MS = 2000;
|
|
|
75
75
|
const RERENDER_MIN_INTERVAL_MS = 550;
|
|
76
76
|
/** Quiet time after the pipeline settles before an edit counts as stopped (the catch-up renders every picture). */
|
|
77
77
|
const EDIT_QUIET_MS = 600;
|
|
78
|
+
/** An announced export that has not gone out after this long is lost: it stops holding the edit open. */
|
|
79
|
+
const EXPORT_PENDING_MAX_MS = 5000;
|
|
78
80
|
|
|
79
81
|
/** `current` in order, then any of `extra` not already in it. */
|
|
80
82
|
function mergeMockupIds(current: readonly string[], extra: readonly string[]): string[] {
|
|
@@ -665,6 +667,11 @@ export function RealtimeProvider({
|
|
|
665
667
|
const pictureViewsRef = useRef<Map<string, PictureView>>(new Map());
|
|
666
668
|
const editLiveRef = useRef(false);
|
|
667
669
|
const editQuietTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
670
|
+
// An export announced (notifyPendingExport) but not sent yet: when it started, or 0. While it is pending, the edit is
|
|
671
|
+
// still going, whatever older version settles meanwhile (slow phone link, 2026-11-11: the editor-open frames were
|
|
672
|
+
// still landing when the drag began; their settle + 600 ms quiet fired a 31-picture catch-up mid-gesture, and the
|
|
673
|
+
// edit's own frames queued behind it for 21 s). Older than EXPORT_PENDING_MAX_MS = lost: it no longer holds the edit.
|
|
674
|
+
const exportPendingSinceRef = useRef(0);
|
|
668
675
|
const shapeApplyTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
669
676
|
const lastShapeRef = useRef<SessionShape | null>(null);
|
|
670
677
|
const applySessionShapeRef = useRef<(() => void) | null>(null);
|
|
@@ -1090,6 +1097,7 @@ export function RealtimeProvider({
|
|
|
1090
1097
|
// frames never all arrive (a failed mockup) is forgotten after 10 s so
|
|
1091
1098
|
// it cannot wedge the policy. Blob sends keep the throttle-queue rule.
|
|
1092
1099
|
let settledVersions = 0;
|
|
1100
|
+
let newestSettled = 0;
|
|
1093
1101
|
const due = dueByVersionRef.current;
|
|
1094
1102
|
results.forEach((result) => {
|
|
1095
1103
|
const v = result.requestVersion;
|
|
@@ -1099,6 +1107,7 @@ export function RealtimeProvider({
|
|
|
1099
1107
|
if (entry.due <= 1) {
|
|
1100
1108
|
due.delete(v);
|
|
1101
1109
|
settledVersions += 1;
|
|
1110
|
+
newestSettled = Math.max(newestSettled, v);
|
|
1102
1111
|
} else {
|
|
1103
1112
|
entry.due -= 1;
|
|
1104
1113
|
}
|
|
@@ -1110,15 +1119,19 @@ export function RealtimeProvider({
|
|
|
1110
1119
|
if (!pipelineResetCooldownRef.current) {
|
|
1111
1120
|
hasBlobInFlightRef.current = false;
|
|
1112
1121
|
for (let i = 0; i < settledVersions; i++) pipelineSettledSubscribersRef.current.forEach((cb) => cb());
|
|
1113
|
-
|
|
1122
|
+
// The EDIT settles only when its newest version has landed and no further export is on its way: an older
|
|
1123
|
+
// version (the editor-open frames on a slow link) settling mid-gesture is not the edit stopping.
|
|
1124
|
+
const exportPending =
|
|
1125
|
+
exportPendingSinceRef.current > 0 && Date.now() - exportPendingSinceRef.current < EXPORT_PENDING_MAX_MS;
|
|
1126
|
+
if (!exportPending && newestSettled >= getLastSentVersion()) markEditSettled();
|
|
1114
1127
|
}
|
|
1115
1128
|
} else if (due.size === 0 && hasBlobInFlightRef.current && !hasPendingBlobs() && !pipelineResetCooldownRef.current) {
|
|
1116
1129
|
hasBlobInFlightRef.current = false;
|
|
1117
1130
|
pipelineSettledSubscribersRef.current.forEach((cb) => cb());
|
|
1118
|
-
markEditSettled();
|
|
1131
|
+
if (!(exportPendingSinceRef.current > 0 && Date.now() - exportPendingSinceRef.current < EXPORT_PENDING_MAX_MS)) markEditSettled();
|
|
1119
1132
|
}
|
|
1120
1133
|
},
|
|
1121
|
-
[hasPendingBlobs, markEditSettled]
|
|
1134
|
+
[hasPendingBlobs, markEditSettled, getLastSentVersion]
|
|
1122
1135
|
);
|
|
1123
1136
|
|
|
1124
1137
|
/** Composite one cropped frame over its frozen background and deliver it. */
|
|
@@ -1306,6 +1319,7 @@ export function RealtimeProvider({
|
|
|
1306
1319
|
baseThrottleMs?: number
|
|
1307
1320
|
) => {
|
|
1308
1321
|
blobQueuedGenRef.current = pipelineGenRef.current;
|
|
1322
|
+
exportPendingSinceRef.current = 0;
|
|
1309
1323
|
const result = sendCanvasBlobRaw(
|
|
1310
1324
|
placement,
|
|
1311
1325
|
blob,
|
|
@@ -1334,6 +1348,7 @@ export function RealtimeProvider({
|
|
|
1334
1348
|
baseThrottleMs?: number
|
|
1335
1349
|
) => {
|
|
1336
1350
|
blobQueuedGenRef.current = pipelineGenRef.current;
|
|
1351
|
+
exportPendingSinceRef.current = 0;
|
|
1337
1352
|
const result = sendCanvasStateRaw(
|
|
1338
1353
|
placement,
|
|
1339
1354
|
state,
|
|
@@ -1765,6 +1780,7 @@ export function RealtimeProvider({
|
|
|
1765
1780
|
// This fires immediately when a change is detected, before the export completes
|
|
1766
1781
|
const notifyPendingExport = useCallback(
|
|
1767
1782
|
(placement: string) => {
|
|
1783
|
+
exportPendingSinceRef.current = Date.now();
|
|
1768
1784
|
// Skip if this placement is already pending — avoids spamming subscribers
|
|
1769
1785
|
// on every canvas change during drag
|
|
1770
1786
|
if (pendingPlacementsRef.current.has(placement)) {
|
|
@@ -1797,6 +1813,9 @@ export function RealtimeProvider({
|
|
|
1797
1813
|
// notifies cancellation subscribers so loading UI can be dismissed.
|
|
1798
1814
|
const notifyPendingExportCancelled = useCallback(
|
|
1799
1815
|
(placement: string) => {
|
|
1816
|
+
// The export turned out a no-op: it no longer holds the edit open; let it settle.
|
|
1817
|
+
exportPendingSinceRef.current = 0;
|
|
1818
|
+
markEditSettled();
|
|
1800
1819
|
// If we never marked this placement as pending, nothing to do.
|
|
1801
1820
|
if (!pendingPlacementsRef.current.has(placement)) {
|
|
1802
1821
|
return;
|
|
@@ -1821,7 +1840,7 @@ export function RealtimeProvider({
|
|
|
1821
1840
|
|
|
1822
1841
|
pendingExportCancelledSubscribersRef.current.forEach((cb) => cb(placement));
|
|
1823
1842
|
},
|
|
1824
|
-
[productContext?.product?.mockups]
|
|
1843
|
+
[productContext?.product?.mockups, markEditSettled]
|
|
1825
1844
|
);
|
|
1826
1845
|
|
|
1827
1846
|
// ============================================================================
|
|
@@ -114,6 +114,42 @@ describe("viewport policy (phone gallery)", () => {
|
|
|
114
114
|
expect(shapes()).toEqual([`${IDS.join(",")}@1200`]);
|
|
115
115
|
});
|
|
116
116
|
|
|
117
|
+
it("no catch-up mid-gesture: an OLDER version settling while the edit's export is pending is not the edit stopping (slow phone link, 2026-11-11)", async () => {
|
|
118
|
+
const { rerender } = render(<Harness v={1} />);
|
|
119
|
+
await waitFor(() => expect(h.sendConfig).toHaveBeenCalled());
|
|
120
|
+
await act(async () => phoneGallery());
|
|
121
|
+
await wait(150);
|
|
122
|
+
await act(async () => edit()); // v1 (the editor-open state) goes out; its frames are slow to land
|
|
123
|
+
h.sendConfig.mockClear();
|
|
124
|
+
// The drag begins: its export is announced, but the page takes 2.7 s to produce it (starved phone).
|
|
125
|
+
await act(async () => ctx.notifyPendingExport("Front"));
|
|
126
|
+
// Meanwhile v1's frames land (all of its set) and v1 settles.
|
|
127
|
+
h.state.results = IDS.map((id) => frame(id, 1));
|
|
128
|
+
await act(async () => rerender(<Harness v={2} />));
|
|
129
|
+
await wait(800);
|
|
130
|
+
expect(shapes()).toEqual([]); // no 6-picture catch-up while the gesture's export is on its way
|
|
131
|
+
await act(async () => edit()); // v2: the drag's state finally goes out
|
|
132
|
+
h.state.results = [frame("M0", 2), frame("M1", 2)];
|
|
133
|
+
await act(async () => rerender(<Harness v={3} />));
|
|
134
|
+
await wait(800);
|
|
135
|
+
expect(shapes()).toEqual([`${IDS.join(",")}@1200`]); // the edit's own frames landed: now catch up
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it("an export that turns out a no-op releases the edit: the catch-up still happens", async () => {
|
|
139
|
+
const { rerender } = render(<Harness v={1} />);
|
|
140
|
+
await waitFor(() => expect(h.sendConfig).toHaveBeenCalled());
|
|
141
|
+
await act(async () => phoneGallery());
|
|
142
|
+
await wait(150);
|
|
143
|
+
await act(async () => edit());
|
|
144
|
+
h.sendConfig.mockClear();
|
|
145
|
+
await act(async () => ctx.notifyPendingExport("Front"));
|
|
146
|
+
h.state.results = IDS.map((id) => frame(id, 1));
|
|
147
|
+
await act(async () => rerender(<Harness v={2} />));
|
|
148
|
+
await act(async () => ctx.notifyPendingExportCancelled("Front"));
|
|
149
|
+
await wait(800);
|
|
150
|
+
expect(shapes()).toEqual([`${IDS.join(",")}@1200`]);
|
|
151
|
+
});
|
|
152
|
+
|
|
117
153
|
it("Done: the slide on screen at hero width, in ONE config", async () => {
|
|
118
154
|
const { rerender } = render(<Harness v={1} />);
|
|
119
155
|
await waitFor(() => expect(h.sendConfig).toHaveBeenCalled());
|