Skip to content

Commit 027236d

Browse files
committed
fix(data): cap paged view wire size at max and prevent short-span reload loop
- wireInput: when the left margin pushes the fetch size past view.max, reduce the margin so the wire limit stays within max. A shown limit above max is sent as-is so the server still refuses it. - adopt: carry the span's reloaded flag forward so a reload triggered by pending edits does not repeat when the server returns data that still lacks those edits.
1 parent 60979a5 commit 027236d

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

‎packages/octane/src/data/store.ts‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,13 @@ function shown(entry: Entry): { offset: number; limit: number } {
220220
function wireInput(entry: Entry): unknown {
221221
if (!isView(entry.read)) return entry.input;
222222
const { offset, limit } = shown(entry);
223-
const start = Math.max(0, offset - MARGIN);
224-
// The margin gives way to the view's cap; the window itself never does, so the server refuses it.
223+
const max = entry.read.view.max;
224+
let start = Math.max(0, offset - MARGIN);
225+
// When the left margin would push the request past max, sacrifice it so the shown window fits.
226+
// A shown limit above max is not trimmed: the server refuses it.
227+
if (limit <= max) start = Math.max(start, offset + limit - max);
225228
const asked = offset - start + limit;
226-
const count = Math.max(asked, Math.min(entry.read.view.max, asked + MARGIN + 1));
229+
const count = Math.max(asked, Math.min(max, asked + MARGIN + 1));
227230
return { ...(entry.input as object), offset: start, limit: count };
228231
}
229232

@@ -591,7 +594,7 @@ export function createDataStore(options: DataStoreOptions): DataStore {
591594
start: offset,
592595
first: offset > 0 ? (rows[0] ?? null) : null,
593596
last: rows.length < limit ? null : rows[rows.length - 1],
594-
reloaded: false,
597+
reloaded: entry.span?.reloaded ?? false,
595598
};
596599
const { of } = entry.read.view;
597600
const later = reload ?? new Set();

0 commit comments

Comments
 (0)