Skip to content

Commit 170bc1c

Browse files
committed
Use state to set height
1 parent c81a42b commit 170bc1c

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

site/src/pages/WorkspaceBuildPage/WorkspaceBuildPageView.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,14 @@ import {
2424
WorkspaceBuildDataSkeleton,
2525
} from "modules/workspaces/WorkspaceBuildData/WorkspaceBuildData";
2626
import { WorkspaceBuildLogs } from "modules/workspaces/WorkspaceBuildLogs/WorkspaceBuildLogs";
27-
import { HTMLProps, useLayoutEffect, useRef, type FC } from "react";
27+
import {
28+
type CSSProperties,
29+
type FC,
30+
type HTMLProps,
31+
useLayoutEffect,
32+
useRef,
33+
useState,
34+
} from "react";
2835
import { Link } from "react-router-dom";
2936
import { displayWorkspaceBuildDuration } from "utils/workspace";
3037
import { Sidebar, SidebarCaption, SidebarItem } from "./Sidebar";
@@ -212,6 +219,7 @@ const ScrollArea: FC<HTMLProps<HTMLDivElement>> = () => {
212219
// Issue: https://github.com/coder/coder/issues/9687
213220
// Reference: https://stackoverflow.com/questions/43381836/height100-works-in-chrome-but-not-in-safari
214221
const contentRef = useRef<HTMLDivElement>(null);
222+
const [height, setHeight] = useState<CSSProperties["width"]>("100%");
215223
useLayoutEffect(() => {
216224
const contentEl = contentRef.current;
217225
if (!contentEl) {
@@ -223,7 +231,7 @@ const ScrollArea: FC<HTMLProps<HTMLDivElement>> = () => {
223231
if (!parentEl) {
224232
return;
225233
}
226-
contentEl.style.setProperty("height", `${parentEl.clientHeight}px`);
234+
setHeight(parentEl.clientHeight);
227235
});
228236
resizeObserver.observe(document.body);
229237

@@ -233,10 +241,7 @@ const ScrollArea: FC<HTMLProps<HTMLDivElement>> = () => {
233241
}, []);
234242

235243
return (
236-
<div
237-
ref={contentRef}
238-
css={{ height: "100%", overflowY: "auto", width: "100%" }}
239-
/>
244+
<div ref={contentRef} css={{ height, overflowY: "auto", width: "100%" }} />
240245
);
241246
};
242247

0 commit comments

Comments
 (0)