Conform more of the codebase to strictNullChecks (#10666)

* Conform more of the codebase to `strictNullChecks`

* Iterate

* Iterate

* Iterate

* Iterate
This commit is contained in:
Michael Telatynski 2023-04-20 09:49:10 +01:00 committed by GitHub
parent 8867f1801e
commit 93b4ee654b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 126 additions and 114 deletions

View file

@ -382,13 +382,12 @@ export default class ScrollPanel extends React.Component<IProps> {
}
const itemlist = this.itemlist.current;
const firstTile = itemlist && (itemlist.firstElementChild as HTMLElement);
const contentTop = firstTile && firstTile.offsetTop;
const firstTile = itemlist?.firstElementChild as HTMLElement | undefined;
const fillPromises: Promise<void>[] = [];
// if scrollTop gets to 1 screen from the top of the first tile,
// try backward filling
if (!firstTile || sn.scrollTop - contentTop < sn.clientHeight) {
if (!firstTile || sn.scrollTop - firstTile.offsetTop < sn.clientHeight) {
// need to back-fill
fillPromises.push(this.maybeFill(depth, true));
}
@ -424,7 +423,7 @@ export default class ScrollPanel extends React.Component<IProps> {
// check if unfilling is possible and send an unfill request if necessary
private checkUnfillState(backwards: boolean): void {
let excessHeight = this.getExcessHeight(backwards);
if (excessHeight <= 0) {
if (excessHeight <= 0 || !this.itemlist.current) {
return;
}
@ -617,10 +616,7 @@ export default class ScrollPanel extends React.Component<IProps> {
* node (specifically, the bottom of it) will be positioned. If omitted, it
* defaults to 0.
*/
public scrollToToken = (scrollToken: string, pixelOffset: number, offsetBase: number): void => {
pixelOffset = pixelOffset || 0;
offsetBase = offsetBase || 0;
public scrollToToken = (scrollToken: string, pixelOffset = 0, offsetBase = 0): void => {
// set the trackedScrollToken, so we can get the node through getTrackedNode
this.scrollState = {
stuckAtBottom: false,
@ -652,6 +648,7 @@ export default class ScrollPanel extends React.Component<IProps> {
const viewportBottom = scrollNode.scrollHeight - (scrollNode.scrollTop + scrollNode.clientHeight);
const itemlist = this.itemlist.current;
if (!itemlist) return;
const messages = itemlist.children;
let node: HTMLElement | null = null;
@ -705,7 +702,7 @@ export default class ScrollPanel extends React.Component<IProps> {
this.bottomGrowth += bottomDiff;
scrollState.bottomOffset = newBottomOffset;
const newHeight = `${this.getListHeight()}px`;
if (itemlist.style.height !== newHeight) {
if (itemlist && itemlist.style.height !== newHeight) {
itemlist.style.height = newHeight;
}
debuglog("balancing height because messages below viewport grew by", bottomDiff);
@ -755,7 +752,7 @@ export default class ScrollPanel extends React.Component<IProps> {
const scrollState = this.scrollState;
if (scrollState.stuckAtBottom) {
if (itemlist.style.height !== newHeight) {
if (itemlist && itemlist.style.height !== newHeight) {
itemlist.style.height = newHeight;
}
if (sn.scrollTop !== sn.scrollHeight) {
@ -770,7 +767,7 @@ export default class ScrollPanel extends React.Component<IProps> {
// the currently filled piece of the timeline
if (trackedNode) {
const oldTop = trackedNode.offsetTop;
if (itemlist.style.height !== newHeight) {
if (itemlist && itemlist.style.height !== newHeight) {
itemlist.style.height = newHeight;
}
const newTop = trackedNode.offsetTop;
@ -823,9 +820,9 @@ export default class ScrollPanel extends React.Component<IProps> {
private getMessagesHeight(): number {
const itemlist = this.itemlist.current;
const lastNode = itemlist.lastElementChild as HTMLElement;
const lastNode = itemlist?.lastElementChild as HTMLElement;
const lastNodeBottom = lastNode ? lastNode.offsetTop + lastNode.clientHeight : 0;
const firstNodeTop = itemlist.firstElementChild ? (itemlist.firstElementChild as HTMLElement).offsetTop : 0;
const firstNodeTop = (itemlist?.firstElementChild as HTMLElement)?.offsetTop ?? 0;
// 18 is itemlist padding
return lastNodeBottom - firstNodeTop + 18 * 2;
}
@ -865,8 +862,8 @@ export default class ScrollPanel extends React.Component<IProps> {
*/
public preventShrinking = (): void => {
const messageList = this.itemlist.current;
const tiles = messageList && messageList.children;
if (!messageList) {
const tiles = messageList?.children;
if (!tiles) {
return;
}
let lastTileNode;