Skip to content

[2.x] fix: data race when cliking on shared media, multiple times - #487

Merged
imorland merged 3 commits into
FriendsOfFlarum:2.xfrom
grimur82:gvn/fix_shared_media_data_race_2x
Sep 2, 2026
Merged

imorland merged 3 commits into
FriendsOfFlarum:2.xfrom
grimur82:gvn/fix_shared_media_data_race_2x

Conversation

@grimur82

Copy link
Copy Markdown
Contributor

Fixes #0000

Changes proposed in this pull request:

Reviewers should focus on:

Screenshot

Confirmed

  • Frontend changes: tested on a local Flarum installation.
  • Backend changes: tests are green (run composer test).

Required changes:

@grimur82
grimur82 requested a review from a team as a code owner April 27, 2026 16:35
@rafaucau rafaucau changed the title fix: data race when cliking on shared media, multiple times [2.x] fix: data race when cliking on shared media, multiple times May 8, 2026
@imorland
imorland force-pushed the gvn/fix_shared_media_data_race_2x branch from 97099a3 to 5bc6973 Compare September 2, 2026 16:42
grimur82 and others added 2 commits September 2, 2026 18:45
Builds on the original fix, which guarded in SharedFileList.loadFileList.
The invariant being protected — parseResults concatenating unconditionally
— lives in FileListState, so guarding at the component left the other two
entry points open:

- loadMore() computes its offset from files.length, so two concurrent
  calls both requested the same page and appended it twice.
- refresh() calls loadResults() directly, so the admin Shared Uploads
  refresh button was unprotected.

Guarding inside loadResults() covers all three, and lets loadMore() drop
its own `loading = true` which would otherwise have tripped the new
guard. refresh() clears the flag deliberately so a deliberate refresh is
never turned into a no-op.

Also replaces the rethrow in the catch block. Every caller ignores the
returned promise, so rethrowing only produced an unhandled rejection with
nothing shown to the reader — and because the list renders "empty"
whenever it has no files and is not loading, a failed request looked
exactly like an empty library. The error is surfaced through a loadError
flag and its own message instead.
@imorland
imorland force-pushed the gvn/fix_shared_media_data_race_2x branch from 5bc6973 to b5f549f Compare September 2, 2026 17:47
setUser() clears files but was not clearing loading, so switching to a
different user while a request was still running returned early from
loadResults(). The new user's list was never fetched and they were left
looking at an empty one — a regression from moving the guard into the
state, since previously nothing blocked that call.

Same one-line fix already applied to refresh().
@imorland
imorland merged commit b400cdf into FriendsOfFlarum:2.x Sep 2, 2026
21 checks passed
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.

2 participants