Repository navigation
fix(web): stop the Autoscan tab crashing when opened directly - #1927
Conversation
Opening /admin/libraries?tab=autoscan directly (a refresh, a bookmark or the old /admin/autoscan link) crashed with React error Silo-Server#185. While the libraries query loaded, the page fell back to a new empty array on every render, so the effect that copies libraries into the reorder state ran on every render. The Autoscan header switch updates state from a ref during commit, and the endless re-renders pushed it past React's nested update limit. Use a stable empty array as the fallback.
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (2)
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review. 📝 WalkthroughWalkthroughAdminLibraries uses stable empty-array fallbacks when library and active-scan query data is unavailable. Its tests share a QueryClient-and-router wrapper and check that loading continues after rerendering. ChangesAdmin Libraries Loading
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Suggested reviewers: Merge Risk: ⚪ Minimal · up to No actionable current-head risk remains. The loading fix and its regression check support merging after normal checks. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
#1232 C1 currently says Not run, with no failed/blocked result or linked blocker, so this PR does not unblock a recorded case. The diff stabilizes direct loading into the Autoscan panel C1 exercises; its source, connection, mapping, and activity workflows are unchanged. This is a minor entry-point change, and C1 still needs its first validation on a published build. Suggested fix: Replace the PR line with: Automated check: Macroscope check run agent (gpt-6-luna). No validation was performed. Posted via Macroscope — v1 validation impact |
|
Right, both cases are still recorded as Not run, so there is nothing to unblock. Updated the line to |
Quick104
left a comment
There was a problem hiding this comment.
The fix is correct. The stable fallback stops the reorder-state effect from setting state on every render, and every route onto the Autoscan tab goes through line 177. AdminLibraries.test.tsx passes on this head (16/16). The inline comments cover the regression test, which hangs instead of failing when the fix is reverted, the remaining copy of libraries into state, and two nits.
Two older issues in the reorder state, outside this diff (lines 217 and 246). Both predate this PR and share the repair in the line 177 comment:
- Low: a refetch during a reorder snaps the dragged row back. If a scan finishes while the reorder request is in flight, the scans event invalidates the libraries query. The refetch returns the old order as a new array, and the effect at line 217 overwrites the dragged order. The row jumps back, then forward again when the reorder succeeds. A second drag in that window sends an order built from the reverted list.
- Low: a failed reorder can restore a stale list.
onError: () => setOrderedLibraries(prev)(line 246) restores the list from drag time even if a refetch landed in between, for example after a library was deleted.useReorderLibrariesdoesn't invalidate on error, andlibrarieshasn't changed since that refetch, so the stale rows stay until the next invalidation.
Both come from reading the code; I didn't reproduce them in a browser.
Needs your call: #1232 C1 is recorded as Not run. CLAUDE.md asks the Validation tasks: line to list the passed cases a change could reach, which would make it Validation tasks: none. The current wording follows the Macroscope suggestion, so this is a question of maintainer convention.
AI disclosure: review by claude-opus-5-5 (with claude-sonnet-5-5 subagents) in Claude Code via T3 Code, /silo code-review.
| const view = render(page()); | ||
| mocks.useAdminLibraries.mockClear(); | ||
|
|
||
| // Any unrelated update (another query resolving) re-renders the page. | ||
| view.rerender(page()); | ||
|
|
||
| expect(screen.getByText("Loading libraries...")).toBeInTheDocument(); | ||
| expect(mocks.useAdminLibraries.mock.calls.length).toBeLessThan(5); |
There was a problem hiding this comment.
Medium: this test hangs instead of failing if the fix regresses.
With line 177 reverted to data: libraries = [], the render loop starts inside the first render(page()), so render never returns. I ran this test against that revert: no output after about three minutes, memory past 2.8 GB, and the worker had to be killed. Vitest's per-test timeout can't interrupt a synchronous loop, so CI would show a stuck or out-of-memory job instead of a failure that names this test. On the fixed code, toBeLessThan(5) passes trivially (the hook is called once per rerender), and it would still pass with up to four extra renders.
Suggested repair: make a loop fail fast inside the first render. For example, count calls in a mockImplementation and throw once the count passes a small bound, or wrap the page in a React.Profiler and fail on too many commits. Then tighten the last check to toHaveBeenCalledTimes(1). Please confirm the new version fails, rather than hangs, with the fix reverted.
There was a problem hiding this comment.
Fixed in a56f710: the mocked hook now throws once the page renders more than 20 times, so with the fix reverted the test fails in about 20 ms with "AdminLibraries re-rendered in a loop while loading" instead of hanging, and the rerender check is now toHaveBeenCalledTimes(1).
| } | ||
|
|
||
| const { data: libraries = [], isLoading } = useAdminLibraries(); | ||
| const { data: libraries = NO_LIBRARIES, isLoading } = useAdminLibraries(); |
There was a problem hiding this comment.
Low, needs your call (this PR or a follow-up): the fix depends on libraries keeping the same reference.
This line is now the only thing preventing the #185 loop. The underlying pattern is still there: orderedLibraries copies libraries into state (line 210), and the effect at lines 217–219 calls setOrderedLibraries(libraries) whenever the reference changes. Any later change that hands the effect a new array on each render brings the crash back: a select in useAdminLibraries, a ?? [] here, or a filter or sort before the effect. The new test mocks the hook, so it wouldn't catch the select case.
Suggested repair: stop copying the query data into state. Keep only a pending order (useState<Library[] | null>(null)), render pendingOrder ?? libraries, and clear it when the reorder mutation settles. Or apply the reorder optimistically in useReorderLibraries (cancelQueries and setQueryData in onMutate, restore in onError). Either one removes the effect, and with it the two reorder races in the review summary. It's a larger change than this crash fix, so a follow-up issue seems reasonable.
| const client = new QueryClient({ defaultOptions: { queries: { retry: false } } }); | ||
| const page = () => ( | ||
| <QueryClientProvider client={client}> | ||
| <MemoryRouter> | ||
| <AdminLibraries /> | ||
| </MemoryRouter> | ||
| </QueryClientProvider> | ||
| ); |
There was a problem hiding this comment.
Nit: third copy of the page's provider tree.
renderPage and renderInteractivePage (lines 131–151) already build this QueryClient → QueryClientProvider → MemoryRouter → AdminLibraries tree. They can't be reused here as written, because rerender needs the element and they don't expose it. A shared element factory, such as const page = (client: QueryClient) => (...), used by both helpers and this test, would keep a future provider change in one place.
There was a problem hiding this comment.
Fixed in a56f710: page(client) builds the provider tree once, and renderPage, renderInteractivePage and this test all use it.
| const { data: libraries = [], isLoading } = useAdminLibraries(); | ||
| const { data: libraries = NO_LIBRARIES, isLoading } = useAdminLibraries(); | ||
| const { data: libraryCapabilities } = useLibraryCapabilities(); | ||
| const { data: activeScans = [] } = useActiveScans(); |
There was a problem hiding this comment.
Nit, optional: the same = [] default one line down.
activeScans gets a new array on every render until useActiveScans resolves. It only feeds the useMemos at lines 271 and 283, with no effect, and the query resolves almost immediately, so the cost is negligible. A NO_ACTIVE_SCANS constant next to NO_LIBRARIES would keep the two defaults consistent.
There was a problem hiding this comment.
Done in a56f710: activeScans falls back to a stable NO_ACTIVE_SCANS next to NO_LIBRARIES.
The regression test now throws from the mocked hook once the page renders in a loop, so a reverted fix fails the test in milliseconds instead of exhausting the worker, and the rerender check expects exactly one call. The three tests share one provider-tree factory, and the active-scans fallback uses a stable empty array like the libraries one.
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
Brings in main's fix for the Autoscan tab crash on direct open (Silo-Server#1927). SourcesPanel.tsx keeps this branch's version: main's copy is Silo-Server#1928's head, which this branch already contains. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Problem
Related issue: #1230
Validation tasks: changes #1232 C1
Opening the Autoscan tab directly crashes the admin page with "Something went wrong" (React error #185). That covers a refresh of
/admin/libraries?tab=autoscan, a bookmark, and the old/admin/autoscanlink the dashboard widgets still use. Clicking the tab from the Libraries tab works, so the crash only shows up when the page loads straight into it.While the libraries query is loading,
AdminLibrariesfalls back to a new[]on every render. The effect that copies libraries into the drag-and-drop reorder state depends on that array, so it runs and sets state on every render until the query resolves. On the Libraries tab that only wastes renders. On the Autoscan tab, the header switch (Radix) sets state from a ref during each commit, and the endless re-renders push it past React's nested-update limit.Approach
Use one stable empty array as the fallback, so the effect only runs when the libraries actually change.
Validation
AdminLibrariestest re-renders the page while libraries are still loading; before the fix it fails with a render-loop error instead of hanging the worker, after it the page renders once./admin/autoscanlink and?view=activityalso render.gofmt,go vet,make lint-changed(0 issues), web lint, format check, build and budget, everyverify-*target and the router artifact test pass. DB-backed tests for the touched packages (autoscan,scanqueue,scanner,libraryingest,taskmanager,scantrigger,adminjob) pass against a freshly migrated database.make test-gofails only inplayback,jellycompat,transcodenode,api/handlersandapiv2tests that also fail on unmodifiedmainon this macOS host: hardware-probe tests whose fake ffmpeg is killed, transcode-session timing under full-suite load, andTestAdminResourceCapabilitiesAndScope. None of them exercise changed code.make test-webhad one failure under full-suite load (AdminUsersrow actions) that passes on its own. Linux CI is the authority for these.go vetand the tests of the packages it changes (apart fromTestAdminResourceCapabilitiesAndScopeabove); web PRs also pass the typecheck and the autoscan web tests. Every pair of the eleven PRs merges cleanly intomainin either order.Risks
None identified.
Checklist
AI Disclosure
mainat medium effort (a Claude Code review agent on claude-opus-5-5, and Codex CLI with gpt-6.1-sol and gpt-6-astra) checked correctness, React state/effect behavior, stale-request guards and docs. No findings for this change.Note
Fix Autoscan tab crash when opened directly in AdminLibraries
Macroscope summarized a56f710.