@@ -45,6 +45,12 @@ export type ScrollCaptureRefusal = { reason: 'no-capture' | 'sparse-tree'; detai
4545/** What one edge capture yields: an analyzed state, or the refusal that kept it from being read. */
4646export type ScrollEdgeObservation = ScrollEdgeState | { refused : ScrollCaptureRefusal } ;
4747
48+ function isScrollEdgeRefused (
49+ observation : ScrollEdgeObservation ,
50+ ) : observation is { refused : ScrollCaptureRefusal } {
51+ return 'refused' in observation ;
52+ }
53+
4854export type ScrollEdgeTarget = {
4955 point ?: Point ;
5056 nodeIndex ?: number ;
@@ -140,10 +146,10 @@ export function scrollSurfaceIsStuck(recentSignatures: readonly string[]): boole
140146/**
141147 * Records one pass's surface signature, capped to the trailing window the stuck detector reads. An
142148 * empty signature is skipped so a container with no positioned descendants stays on its edge/pass
143- * signals instead of stacking blanks. Both scroll loops push through here so "one window" has one
144- * definition rather than a copy that can drift .
149+ * signals instead of stacking blanks. `runScrollPasses` is its one caller, so every scroll loop
150+ * reads the same window .
145151 */
146- export function pushScrollSurfaceSignature (
152+ function pushScrollSurfaceSignature (
147153 recentSignatures : string [ ] ,
148154 fingerprint : string | undefined ,
149155 window : number ,
@@ -206,7 +212,8 @@ export async function runScrollEdgePasses<TResult>(params: {
206212 edge : ScrollEdge ;
207213 captureState : ( scope ?: string ) => Promise < ScrollEdgeObservation > ;
208214 scroll : ( ) => Promise < TResult > ;
209- settleAfterPass ?: ( ) => Promise < void > ;
215+ /** The rest-wait, handed the scope the loop is deciding on so it watches the same container. */
216+ settleAfterPass ?: ( scope : string | undefined ) => Promise < void > ;
210217} ) : Promise < { passes : number ; result ?: TResult } > {
211218 const { edge, captureState, scroll, settleAfterPass } = params ;
212219 // The first capture discovers the container; every later one reads the scope the previous state
@@ -217,18 +224,20 @@ export async function runScrollEdgePasses<TResult>(params: {
217224 let observation = await captureState ( scope ) ;
218225 if ( ! discovered ) {
219226 discovered = true ;
220- if ( ! ( 'refused' in observation ) && observation . scope ) {
227+ if ( ! isScrollEdgeRefused ( observation ) && observation . scope ) {
221228 observation = await captureState ( observation . scope ) ;
222229 }
223230 }
224- if ( ! ( 'refused' in observation ) ) scope = observation . scope ;
231+ if ( ! isScrollEdgeRefused ( observation ) ) scope = observation . scope ;
225232 return observation ;
226233 } ;
227234 return await runScrollPasses ( {
228235 observe,
229236 refuse : ( observation ) =>
230- 'refused' in observation ? buildScrollEdgeCaptureError ( edge , observation . refused ) : undefined ,
231- shouldStop : async ( observation ) => ! ( 'refused' in observation ) && ! observation . canScroll ,
237+ isScrollEdgeRefused ( observation )
238+ ? buildScrollEdgeCaptureError ( edge , observation . refused )
239+ : undefined ,
240+ shouldStop : async ( observation ) => ! isScrollEdgeRefused ( observation ) && ! observation . canScroll ,
232241 passLimit : SCROLL_EDGE_PASS_LIMIT ,
233242 passLimitError : ( passes ) =>
234243 new AppError (
@@ -242,10 +251,10 @@ export async function runScrollEdgePasses<TResult>(params: {
242251 } ,
243252 ) ,
244253 fingerprint : async ( observation ) =>
245- 'refused' in observation ? undefined : observation . fingerprint ,
254+ isScrollEdgeRefused ( observation ) ? undefined : observation . fingerprint ,
246255 noProgressError : ( passes ) => buildScrollEdgeNoProgressError ( edge , passes ) ,
247256 scroll,
248- ...( settleAfterPass ? { settleAfterPass } : { } ) ,
257+ ...( settleAfterPass ? { settleAfterPass : async ( ) => await settleAfterPass ( scope ) } : { } ) ,
249258 } ) ;
250259}
251260
0 commit comments