Skip to content

Commit 4121121

Browse files
fix(site): prevent overwriting of newest workspace data during optimistic updates (coder#10751)
1 parent 71f87d0 commit 4121121

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

site/e2e/helpers.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
RichParameter,
1717
} from "./provisionerGenerated";
1818
import { prometheusPort, pprofPort } from "./constants";
19-
import { port, TEST_TIMEOUT } from "./playwright.config";
19+
import { port } from "./playwright.config";
2020
import * as ssh from "ssh2";
2121
import { Duplex } from "stream";
2222
import { WorkspaceBuildParameter } from "api/typesGenerated";
@@ -197,7 +197,6 @@ export const stopWorkspace = async (page: Page, workspaceName: string) => {
197197
"span[data-testid='build-status'] >> text=Stopped",
198198
{
199199
state: "visible",
200-
timeout: TEST_TIMEOUT * 2,
201200
},
202201
);
203202
};

site/e2e/playwright.config.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ const coderMain = path.join(__dirname, "../../enterprise/cmd/coder");
1212

1313
export const STORAGE_STATE = path.join(__dirname, ".auth.json");
1414

15-
export const TEST_TIMEOUT = 60_000;
16-
1715
const localURL = (port: number, path: string): string => {
1816
return `http://localhost:${port}${path}`;
1917
};
@@ -31,7 +29,7 @@ export default defineConfig({
3129
use: {
3230
storageState: STORAGE_STATE,
3331
},
34-
timeout: TEST_TIMEOUT,
32+
timeout: 60_000,
3533
},
3634
],
3735
reporter: [["./reporter.ts"]],

site/src/api/queries/workspaces.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,18 @@ const updateWorkspaceBuild = async (
249249
build.workspace_name,
250250
);
251251
const previousData = queryClient.getQueryData(workspaceKey) as Workspace;
252-
queryClient.setQueryData(workspaceKey, {
253-
...previousData,
254-
latest_build: build,
255-
});
252+
253+
// Check if the build returned is newer than the previous build that could be
254+
// updated from web socket
255+
const previousUpdate = new Date(previousData.latest_build.updated_at);
256+
const newestUpdate = new Date(build.updated_at);
257+
if (newestUpdate > previousUpdate) {
258+
queryClient.setQueryData(workspaceKey, {
259+
...previousData,
260+
latest_build: build,
261+
});
262+
}
263+
256264
await queryClient.invalidateQueries({
257265
queryKey: workspaceBuildsKey(build.workspace_id),
258266
});

0 commit comments

Comments
 (0)