@@ -69,6 +69,11 @@ export function serializeLoadSubsetOptions(
6969 result . limit = options . limit
7070 }
7171
72+ // Include offset for pagination support - different offsets need different query keys
73+ if ( options . offset !== undefined ) {
74+ result . offset = options . offset
75+ }
76+
7277 return JSON . stringify ( Object . keys ( result ) . length === 0 ? null : result )
7378}
7479
@@ -158,7 +163,7 @@ function isBasicExpression(
158163}
159164
160165/**
161- * Apply LoadSubsetOptions to data (filter, sort, limit)
166+ * Apply LoadSubsetOptions to data (filter, sort, limit, offset )
162167 */
163168export function applyPredicates < T > (
164169 data : Array < T > ,
@@ -172,6 +177,7 @@ export function applyPredicates<T>(
172177 let filters : Array < SimpleComparison > = [ ]
173178 let sorts : Array < ParsedOrderBy > = [ ]
174179 let limit : number | undefined = undefined
180+ const offset = options . offset ?? 0
175181
176182 // Check if where clause is simple before trying to parse
177183 const hasComplexWhere = options . where && ! isSimpleExpression ( options . where )
@@ -232,6 +238,7 @@ export function applyPredicates<T>(
232238 expressionSummary : analysis ,
233239 hasOrderBy : Boolean ( orderBy ) ,
234240 limit : rawLimit ,
241+ offset,
235242 filtersCount : filters . length ,
236243 sortsCount : sorts . length ,
237244 initialSize : data . length ,
@@ -261,14 +268,16 @@ export function applyPredicates<T>(
261268 }
262269 }
263270
264- // Apply LIMIT
265- // Note: offset is NOT applied here - it's handled by the live query windowing layer
266- // The limit passed here already accounts for offset (e.g., offset(20).limit(10) -> limit: 30)
267- if ( limit !== undefined ) {
268- result = result . slice ( 0 , limit )
271+ // Apply OFFSET and LIMIT
272+ // For pagination: offset skips rows, limit caps the result
273+ if ( offset > 0 || limit !== undefined ) {
274+ const start = offset
275+ const end = limit !== undefined ? offset + limit : undefined
276+ result = result . slice ( start , end )
269277 if ( DEBUG_SUMMARY ) {
270- console . log ( `[query-filter] after limit` , {
278+ console . log ( `[query-filter] after offset/ limit` , {
271279 size : result . length ,
280+ offset,
272281 limit,
273282 } )
274283 }
0 commit comments