Skip to content

Commit d4e38f5

Browse files
committed
Memoize workspace schedule button
1 parent f0d1481 commit d4e38f5

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

site/src/components/Workspace/Workspace.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { makeStyles } from "@material-ui/core/styles"
2-
import { FC } from "react"
2+
import React, { FC } from "react"
33
import { useNavigate } from "react-router-dom"
44
import * as TypesGen from "../../api/typesGenerated"
55
import { BuildsTable } from "../BuildsTable/BuildsTable"
@@ -14,6 +14,12 @@ import { WorkspaceScheduleButton } from "../WorkspaceScheduleButton/WorkspaceSch
1414
import { WorkspaceSection } from "../WorkspaceSection/WorkspaceSection"
1515
import { WorkspaceStats } from "../WorkspaceStats/WorkspaceStats"
1616

17+
// The WorkspaceScheduleButton does some calculation to display the date labels
18+
// so to avoid doing that every seconds - because of the workspace pooling - we
19+
// are memoizing this component. More details:
20+
// https://github.com/coder/coder/pull/2775#discussion_r912080377
21+
const MemoizedWorkspaceScheduleButton = React.memo(WorkspaceScheduleButton)
22+
1723
export interface WorkspaceProps {
1824
bannerProps: {
1925
isLoading?: boolean
@@ -60,7 +66,7 @@ export const Workspace: FC<WorkspaceProps> = ({
6066
<PageHeader
6167
actions={
6268
<Stack direction="row" spacing={1}>
63-
<WorkspaceScheduleButton
69+
<MemoizedWorkspaceScheduleButton
6470
workspace={workspace}
6571
onDeadlineMinus={scheduleProps.onDeadlineMinus}
6672
onDeadlinePlus={scheduleProps.onDeadlinePlus}

0 commit comments

Comments
 (0)