Skip to content

Commit e0dfc5b

Browse files
fix(ObjectPage): prevent crash on re-mount (#1317)
1 parent 693b1b3 commit e0dfc5b

File tree

3 files changed

+21
-22
lines changed

3 files changed

+21
-22
lines changed

packages/main/src/components/ObjectPage/ObjectPageUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const extractSectionIdFromHtmlId = (id: string) => {
1212
};
1313

1414
export const getLastObjectPageSection = (ref: RefObject<HTMLDivElement>): HTMLElement => {
15-
const sections = ref.current.querySelectorAll<HTMLElement>('[id^="ObjectPageSection"]');
15+
const sections = ref.current?.querySelectorAll<HTMLElement>('[id^="ObjectPageSection"]');
1616
if (!sections || sections.length < 1) {
1717
return null;
1818
}

packages/main/src/components/ObjectPage/index.tsx

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -316,23 +316,31 @@ const ObjectPage: FC<ObjectPagePropTypes> = forwardRef((props: ObjectPagePropTyp
316316

317317
useEffect(() => {
318318
const fillerDivObserver = new ResizeObserver(() => {
319+
let heightDiff = 0;
320+
319321
const maxHeight = Math.min(objectPageRef.current?.clientHeight, window.innerHeight);
320322
const availableScrollHeight = maxHeight - totalHeaderHeight;
321323
const lastSectionDomRef = getLastObjectPageSection(objectPageRef);
322-
const subSections = lastSectionDomRef.querySelectorAll('[id^="ObjectPageSubSection"]');
323324

324-
let lastSubSectionHeight;
325-
if (subSections.length > 0) {
326-
lastSubSectionHeight = (subSections[subSections.length - 1] as HTMLElement).offsetHeight;
327-
} else {
328-
lastSubSectionHeight =
329-
lastSectionDomRef.offsetHeight -
330-
lastSectionDomRef.querySelector<HTMLElement>("[role='heading']").offsetHeight;
331-
}
325+
if (lastSectionDomRef) {
326+
const subSections = lastSectionDomRef.querySelectorAll('[id^="ObjectPageSubSection"]');
327+
328+
let lastSubSectionHeight;
329+
if (subSections.length > 0) {
330+
lastSubSectionHeight = (subSections[subSections.length - 1] as HTMLElement).offsetHeight;
331+
} else {
332+
lastSubSectionHeight =
333+
lastSectionDomRef.offsetHeight -
334+
lastSectionDomRef.querySelector<HTMLElement>("[role='heading']").offsetHeight;
335+
}
336+
337+
heightDiff = Math.max(0, availableScrollHeight - lastSubSectionHeight);
332338

333-
let heightDiff = availableScrollHeight - lastSubSectionHeight;
339+
if (isNaN(heightDiff)) {
340+
heightDiff = 0;
341+
}
342+
}
334343

335-
heightDiff = heightDiff > 0 ? heightDiff : 0;
336344
objectPageRef.current?.style.setProperty(ObjectPageCssVariables.lastSectionMargin, `${heightDiff}px`);
337345
});
338346

yarn.lock

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@
367367
resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.12.11.tgz#c9a1f021917dcb5ccf0d4e453e399022981fc9ed"
368368
integrity sha512-np/lG3uARFybkoHokJUmf1QfEvRVCPbmQeUQpKow5cQ3xWrV9i3rUHodKDJPQfTVX61qKi+UdYk8kik84n7XOw==
369369

370-
"@babel/helper-validator-option@^7.12.16", "@babel/helper-validator-option@^7.12.17":
370+
"@babel/helper-validator-option@^7.12.17":
371371
version "7.12.17"
372372
resolved "https://registry.yarnpkg.com/@babel/helper-validator-option/-/helper-validator-option-7.12.17.tgz#d1fbf012e1a79b7eebbfdc6d270baaf8d9eb9831"
373373
integrity sha512-TopkMDmLzq8ngChwRlyjR6raKD6gMSae4JdYDB8bByKreQgG0RBTuKe9LRxW3wFtUnjxOPRKBDwEH6Mg5KeDfw==
@@ -1233,15 +1233,6 @@
12331233
lodash "^4.17.19"
12341234
to-fast-properties "^2.0.0"
12351235

1236-
"@babel/types@^7.12.17":
1237-
version "7.12.17"
1238-
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.12.17.tgz#9d711eb807e0934c90b8b1ca0eb1f7230d150963"
1239-
integrity sha512-tNMDjcv/4DIcHxErTgwB9q2ZcYyN0sUfgGKUK/mm1FJK7Wz+KstoEekxrl/tBiNDgLK1HGi+sppj1An/1DR4fQ==
1240-
dependencies:
1241-
"@babel/helper-validator-identifier" "^7.12.11"
1242-
lodash "^4.17.19"
1243-
to-fast-properties "^2.0.0"
1244-
12451236
"@base2/pretty-print-object@1.0.0":
12461237
version "1.0.0"
12471238
resolved "https://registry.yarnpkg.com/@base2/pretty-print-object/-/pretty-print-object-1.0.0.tgz#860ce718b0b73f4009e153541faff2cb6b85d047"

0 commit comments

Comments
 (0)