Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: Show the selected link scan report after navigation (#8271)

[._.]/ Adam Eivya1d89edb4017
diff --git a/client/src/pages/BrainScanReport.jsx b/client/src/pages/BrainScanReport.jsx
index 0711fc015d..115e0ae08e 100644
--- a/client/src/pages/BrainScanReport.jsx
+++ b/client/src/pages/BrainScanReport.jsx
@@ -24,16 +24,19 @@ function Shell({ children }) {
export default function BrainScanReport() {
const { id } = useParams();
+ return <ScanReportForLink key={id} id={id} />;
+}
+
+function ScanReportForLink({ id }) {
const fetchReport = useCallback(async () => {
const [link, report] = await Promise.all([
api.getBrainLink(id, { silent: true }),
api.getBrainScanReport(id, { silent: true })
]);
- return { link, report };
+ return { id, link, report };
}, [id]);
const { data, loading, refetch } = useAutoRefetch(fetchReport, 30_000);
-
- if (loading) {
+ if (loading || (data && data.id !== id)) {
return (
<Shell>
<PageSkeleton
diff --git a/client/src/pages/BrainScanReport.test.jsx b/client/src/pages/BrainScanReport.test.jsx
index 59158e5472..40a37d01c9 100644
--- a/client/src/pages/BrainScanReport.test.jsx
+++ b/client/src/pages/BrainScanReport.test.jsx
@@ -1,6 +1,6 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { act, render, screen, waitFor } from '@testing-library/react';
-import { MemoryRouter, Routes, Route } from 'react-router';
+import { MemoryRouter, Routes, Route, useNavigate } from 'react-router';
vi.mock('../services/api', () => ({
getBrainLink: vi.fn(),
@@ -28,6 +28,11 @@ const renderPage = async () => {
return result;
};
+function NavigateToSecondLink() {
+ const navigate = useNavigate();
+ return <button onClick={() => navigate('/brain/links/def/scan-report')}>Second link</button>;
+}
+
// `/brain*` is in Layout's isFullWidth list, so <main> is `overflow-hidden` and
// this page must supply its own scroll container — otherwise a long report is
// clipped with no way to reach the rest of it.
@@ -72,4 +77,38 @@ describe('BrainScanReport', () => {
await waitFor(() => expect(screen.getByText('This scan report is unavailable.')).toBeInTheDocument());
expectOwnScrollContainer(container);
});
+
+ it('fetches the new link immediately and ignores a late response from the previous link', async () => {
+ let resolveFirstReport;
+ let resolveSecondReport;
+ api.getBrainLink.mockImplementation((id) => Promise.resolve({
+ title: id === 'abc' ? 'First link' : 'Second link',
+ url: `https://example.com/${id}`,
+ }));
+ api.getBrainScanReport.mockImplementation((id) => new Promise((resolve) => {
+ if (id === 'abc') resolveFirstReport = resolve;
+ else resolveSecondReport = resolve;
+ }));
+
+ render(
+ <MemoryRouter initialEntries={['/brain/links/abc/scan-report']}>
+ <NavigateToSecondLink />
+ <Routes>
+ <Route path="/brain/links/:id/scan-report" element={<BrainScanReport />} />
+ </Routes>
+ </MemoryRouter>
+ );
+ await waitFor(() => expect(api.getBrainScanReport).toHaveBeenCalledWith('abc', { silent: true }));
+
+ await act(async () => { screen.getByRole('button', { name: 'Second link' }).click(); });
+ await waitFor(() => expect(api.getBrainScanReport).toHaveBeenCalledWith('def', { silent: true }));
+ expect(screen.getByRole('status', { name: 'Loading scan report' })).toBeInTheDocument();
+ expect(screen.queryByText('First link')).not.toBeInTheDocument();
+
+ await act(async () => { resolveSecondReport('Second report'); });
+ expect(await screen.findByText('Second link', { selector: 'h1' })).toBeInTheDocument();
+ await act(async () => { resolveFirstReport('First report'); });
+ expect(screen.getByTestId('markdown')).toHaveTextContent('Second report');
+ expect(screen.queryByText('First link')).not.toBeInTheDocument();
+ });
});