Skip to content

Commit c98ad4c

Browse files
committed
feat: allow null value for schedulingStrategy in FinderOptions and update documentation accordingly.
1 parent a69d4d8 commit c98ad4c

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

.changeset/small-houses-fix.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@sec-ant/finder": minor
3+
---
4+
5+
Update schedulingStrategy option to allow null value in FinderOptions.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ Maximum number of path checks before attempting to generate a selector. Defaults
106106

107107
### schedulingStrategy
108108

109-
Defines the scheduling strategy for yielding control to the main thread during selector generation. This helps prevent the page from becoming unresponsive during intensive computations. Possible values are `'interactive'`, `'smooth'`, or `'idle'`. Defaults to `'idle'`.
109+
Defines the scheduling strategy for yielding control to the main thread during selector generation. This helps prevent the page from becoming unresponsive during intensive computations. Possible values are `'interactive'`, `'smooth'`, `'idle'`, or `null`. Defaults to `'idle'`. If `null` is provided, the scheduling strategy will be disabled, and no yielding to the main thread will occur.
110110

111111
### abortSignal
112112

src/index.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export interface FinderOptions {
108108
/** Maximum number of path checks. */
109109
maxNumberOfPathChecks?: number;
110110
/** The scheduling strategy for yielding control to the main thread. */
111-
schedulingStrategy?: SchedulingStrategy;
111+
schedulingStrategy?: SchedulingStrategy | null;
112112
/** An AbortSignal to allow aborting the operation. */
113113
abortSignal?: AbortSignal;
114114
}
@@ -150,7 +150,7 @@ export async function finder(
150150

151151
const startTime = new Date();
152152
const config: ResolvedFinderOptions = { ...defaultOptions, ...options };
153-
const rootDocument = findRootDocument(config.root, defaultOptions); // Cast to satisfy findRootDocument
153+
const rootDocument = findRootDocument(config.root, defaultOptions);
154154

155155
let foundPath: Knot[] | undefined;
156156
let count = 0;
@@ -163,7 +163,9 @@ export async function finder(
163163
}
164164
const candidate = iteratorResult.value;
165165

166-
await yieldOrContinue(config.schedulingStrategy, config.abortSignal);
166+
if (config.schedulingStrategy) {
167+
await yieldOrContinue(config.schedulingStrategy, config.abortSignal);
168+
}
167169

168170
const elapsedTimeMs = new Date().getTime() - startTime.getTime();
169171
if (
@@ -205,7 +207,9 @@ export async function finder(
205207
}
206208
const currentOptimizedPath = iteratorResult.value;
207209
optimizedPaths.push(currentOptimizedPath);
208-
await yieldOrContinue(config.schedulingStrategy, config.abortSignal);
210+
if (config.schedulingStrategy) {
211+
await yieldOrContinue(config.schedulingStrategy, config.abortSignal);
212+
}
209213
}
210214

211215
if (optimizedPaths.length > 0) {

tests/finder.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ async function check(
1515
) {
1616
document.documentElement.innerHTML = html;
1717

18-
const options = {
18+
const options: FinderOptions = {
1919
timeoutMs: Number.POSITIVE_INFINITY,
2020
maxNumberOfPathChecks: 2_000,
2121
...finderOptions,

0 commit comments

Comments
 (0)