Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit ae50eee

Browse files
author
Kerry
authored
Apply strictNullChecks to src/utils/pillify.tsx (#10456)
* apply strictNullChecks to src/utils/pillify.tsx * include change to utility * apply strictNullChecks to src/utils/permalinks
1 parent cd700e2 commit ae50eee

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

src/components/views/elements/Pill.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ export enum PillType {
3737
EventInOtherRoom = "TYPE_EVENT_IN_OTHER_ROOM",
3838
}
3939

40-
export const pillRoomNotifPos = (text: string): number => {
41-
return text.indexOf("@room");
40+
export const pillRoomNotifPos = (text: string | null): number => {
41+
return text?.indexOf("@room") ?? -1;
4242
};
4343

4444
export const pillRoomNotifLen = (): number => {

src/utils/permalinks/Permalinks.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ const ANY_REGEX = /.*/;
8484
export class RoomPermalinkCreator {
8585
private roomId: string;
8686
private highestPlUserId: string | null = null;
87-
private populationMap: { [serverName: string]: number } | null = null;
88-
private bannedHostsRegexps: RegExp[] | null = null;
89-
private allowedHostsRegexps: RegExp[] | null = null;
87+
private populationMap: { [serverName: string]: number } = {};
88+
private bannedHostsRegexps: RegExp[] = [];
89+
private allowedHostsRegexps: RegExp[] = [];
9090
private _serverCandidates?: string[];
9191
private started = false;
9292

src/utils/pillify.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export function pillifyLinks(nodes: ArrayLike<Element>, mxEvent: MatrixEvent, pi
8282
);
8383

8484
ReactDOM.render(pill, pillContainer);
85-
node.parentNode.replaceChild(pillContainer, node);
85+
node.parentNode?.replaceChild(pillContainer, node);
8686
pills.push(pillContainer);
8787
// Pills within pills aren't going to go well, so move on
8888
pillified = true;
@@ -95,10 +95,10 @@ export function pillifyLinks(nodes: ArrayLike<Element>, mxEvent: MatrixEvent, pi
9595
// as applying pills happens outside of react, make sure we're not doubly
9696
// applying @room pills here, as a rerender with the same content won't touch the DOM
9797
// to clear the pills from the last run of pillifyLinks
98-
!node.parentElement.classList.contains("mx_AtRoomPill")
98+
!node.parentElement?.classList.contains("mx_AtRoomPill")
9999
) {
100100
let currentTextNode = node as Node as Text | null;
101-
const roomNotifTextNodes = [];
101+
const roomNotifTextNodes: Text[] = [];
102102

103103
// Take a textNode and break it up to make all the instances of @room their
104104
// own textNode, adding those nodes to roomNotifTextNodes
@@ -109,7 +109,7 @@ export function pillifyLinks(nodes: ArrayLike<Element>, mxEvent: MatrixEvent, pi
109109
let roomTextNode = currentTextNode;
110110

111111
if (roomNotifPos > 0) roomTextNode = roomTextNode.splitText(roomNotifPos);
112-
if (roomTextNode.textContent.length > pillRoomNotifLen()) {
112+
if (roomTextNode.textContent && roomTextNode.textContent.length > pillRoomNotifLen()) {
113113
nextTextNode = roomTextNode.splitText(pillRoomNotifLen());
114114
}
115115
roomNotifTextNodes.push(roomTextNode);
@@ -140,7 +140,7 @@ export function pillifyLinks(nodes: ArrayLike<Element>, mxEvent: MatrixEvent, pi
140140
);
141141

142142
ReactDOM.render(pill, pillContainer);
143-
roomNotifTextNode.parentNode.replaceChild(pillContainer, roomNotifTextNode);
143+
roomNotifTextNode.parentNode?.replaceChild(pillContainer, roomNotifTextNode);
144144
pills.push(pillContainer);
145145
}
146146
// Nothing else to do for a text node (and we don't need to advance

0 commit comments

Comments
 (0)