Skip to content

Fix FilePickerWebOptions.readSequential having no effect - #2207

Merged
vicajilau merged 4 commits into
mainfrom
fix/web-read-sequential-noop
Sep 13, 2026
Merged

vicajilau merged 4 commits into
mainfrom
fix/web-read-sequential-noop

Conversation

@vicajilau

Copy link
Copy Markdown
Owner

Fixes #2206.

The bug

FilePickerWeb._processSelectedFiles processed the picked FileList with a single for loop that awaited each file in turn, with no branch on readSequential anywhere and no parallel code path at all. The flag never did anything regardless of its value. Confirmed by reproducing the exact loop structure against fake delayed reads: max observed concurrency was 1 whether readSequential was true or false.

withData/withReadStream on the same FilePickerWebOptions class were already correctly wired, this was specific to readSequential.

The fix

Extracted the per-file work into an indexed task and added runIndexedTasks (indexed_task_runner.dart), a small internal helper that runs those tasks either one at a time or concurrently via Future.wait, writing results into index-based slots so the output always matches selection order regardless of completion order or concurrency mode.

readSequential: true now genuinely reads one file at a time. readSequential: false (the default) reads them concurrently. Selection order is preserved in the result either way.

Test plan

  • Added indexed_task_runner_test.dart, a plain Dart test (no browser needed) exercising both modes directly: sequential caps concurrency at 1, concurrent allows more than one in flight, both preserve order even when completion order is reversed
  • melos exec -- flutter analyze . clean across all 8 packages
  • melos exec -- flutter test all green across all 8 packages
  • dart format --output=none --set-exit-if-changed . clean

Fixes #2206.

_processSelectedFiles processed the picked FileList with a single for
loop that awaited each file in turn, with no branch on readSequential
and no parallel code path at all, so the flag never did anything
regardless of its value. Confirmed with a reproduction of the exact
loop structure: max observed concurrency was 1 in both cases.

Extracted the per-file work into an indexed task and added
runIndexedTasks, a small internal helper that runs those tasks either
one at a time or concurrently via Future.wait, writing results into
index-based slots so the output always matches selection order
regardless of completion order or concurrency mode.

Added indexed_task_runner_test.dart, a plain Dart test (no browser
needed) that exercises both modes directly: sequential caps
concurrency at 1, concurrent allows more than one in flight, and both
preserve order even when completion order is reversed.
Comment thread packages/file_picker_web/lib/src/indexed_task_runner.dart Outdated
Comment thread packages/file_picker_web/lib/src/indexed_task_runner.dart Outdated
Comment thread packages/file_picker_web/lib/src/indexed_task_runner.dart
Comment thread packages/file_picker_web/lib/src/indexed_task_runner.dart Outdated
Future.wait() already returns results in the order the futures were
passed in, not completion order, so the manual index bookkeeping via
a pre-filled nullable list and then() side effects was unnecessary.
Return its result directly in the concurrent branch instead, which
also removes the need for the trailing cast. Restructured the
sequential branch as an early return instead of if/else, and added
an explicit early return for length == 0.
@vicajilau

Copy link
Copy Markdown
Owner Author

Addressed all four comments in 12a8dbf, replied inline on each. Future.wait() already preserves input order, so the manual index writes and trailing cast were unnecessary, simplified to return its result directly. All green (analyze/test/format).

@vicajilau
vicajilau enabled auto-merge September 13, 2026 09:39
@vicajilau
vicajilau disabled auto-merge September 13, 2026 09:44
@vicajilau
vicajilau merged commit 90a28d7 into main Sep 13, 2026
10 of 11 checks passed
@vicajilau
vicajilau deleted the fix/web-read-sequential-noop branch September 13, 2026 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

file_picker_web: FilePickerWebOptions.readSequential has no effect

2 participants