Skip to content

Commit fda4a03

Browse files
committed
fix more components
1 parent 55c8466 commit fda4a03

File tree

5 files changed

+34
-29
lines changed

5 files changed

+34
-29
lines changed

src/render/ChapterVote.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import * as React from "react";
2-
import * as ReactDOM from "react-dom";
2+
import { createRoot, Root } from 'react-dom/client';
33
import ChapterVoteComponent, { ChapterVoteState } from "../components/ChapterVoteComponent";
44
import { VoteResponse } from "../messageTypes";
55
import { Category, SegmentUUID, SponsorTime } from "../types";
66

77
export class ChapterVote {
88
container: HTMLElement;
99
ref: React.RefObject<ChapterVoteComponent>;
10+
root: Root;
1011

1112
unsavedState: ChapterVoteState;
1213

@@ -19,18 +20,16 @@ export class ChapterVote {
1920
this.container.id = "chapterVote";
2021
this.container.style.height = "100%";
2122

22-
ReactDOM.render(
23-
<ChapterVoteComponent ref={this.ref} vote={vote} />,
24-
this.container
25-
);
23+
this.root = createRoot(this.container);
24+
this.root.render(<ChapterVoteComponent ref={this.ref} vote={vote} />);
2625
}
2726

2827
getContainer(): HTMLElement {
2928
return this.container;
3029
}
3130

3231
close(): void {
33-
ReactDOM.unmountComponentAtNode(this.container);
32+
this.root.unmount();
3433
this.container.remove();
3534
}
3635

src/render/GenericNotice.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from "react";
2-
import * as ReactDOM from "react-dom";
2+
import { createRoot, Root } from 'react-dom/client';
33
import NoticeComponent from "../components/NoticeComponent";
44

55
import Utils from "../utils";
@@ -35,6 +35,7 @@ export default class GenericNotice {
3535
noticeElement: HTMLDivElement;
3636
noticeRef: React.MutableRefObject<NoticeComponent>;
3737
idSuffix: string;
38+
root: Root;
3839

3940
constructor(contentContainer: ContentContainer, idSuffix: string, options: NoticeOptions) {
4041
this.noticeRef = React.createRef();
@@ -49,11 +50,13 @@ export default class GenericNotice {
4950

5051
referenceNode.prepend(this.noticeElement);
5152

52-
this.update(options);
53+
this.root = createRoot(this.noticeElement);
54+
55+
this.update(options);
5356
}
5457

5558
update(options: NoticeOptions): void {
56-
ReactDOM.render(
59+
this.root.render(
5760
<NoticeComponent
5861
noticeTitle={options.title}
5962
idSuffix={this.idSuffix}
@@ -92,8 +95,7 @@ export default class GenericNotice {
9295
</>
9396
: null}
9497

95-
</NoticeComponent>,
96-
this.noticeElement
98+
</NoticeComponent>
9799
);
98100
}
99101

@@ -137,7 +139,7 @@ export default class GenericNotice {
137139
}
138140

139141
close(): void {
140-
ReactDOM.unmountComponentAtNode(this.noticeElement);
142+
this.root.unmount();
141143

142144
this.noticeElement.remove();
143145
}

src/render/RectangleTooltip.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from "react";
2-
import * as ReactDOM from "react-dom";
2+
import { createRoot, Root } from 'react-dom/client';
33

44
export interface RectangleTooltipProps {
55
text: string,
@@ -20,7 +20,7 @@ export interface RectangleTooltipProps {
2020
export class RectangleTooltip {
2121
text: string;
2222
container: HTMLDivElement;
23-
23+
root: Root;
2424
timer: NodeJS.Timeout;
2525

2626
constructor(props: RectangleTooltipProps) {
@@ -32,6 +32,7 @@ export class RectangleTooltip {
3232
this.text = props.text;
3333
props.fontSize ??= "10px";
3434

35+
3536
this.container = document.createElement('div');
3637
props.htmlId ??= "sponsorRectangleTooltip" + props.text;
3738
this.container.id = props.htmlId;
@@ -47,7 +48,8 @@ export class RectangleTooltip {
4748
this.timer = setTimeout(() => this.close(), props.timeout * 1000);
4849
}
4950

50-
ReactDOM.render(
51+
this.root = createRoot(this.container);
52+
this.root.render(
5153
<div style={{
5254
bottom: props.bottomOffset,
5355
left: props.leftOffset,
@@ -81,13 +83,12 @@ export class RectangleTooltip {
8183

8284
{chrome.i18n.getMessage("GotIt")}
8385
</button>
84-
</div>,
85-
this.container
86+
</div>
8687
)
8788
}
8889

8990
close(): void {
90-
ReactDOM.unmountComponentAtNode(this.container);
91+
this.root.unmount();
9192
this.container.remove();
9293

9394
if (this.timer) clearTimeout(this.timer);

src/render/SubmissionNotice.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from "react";
2-
import * as ReactDOM from "react-dom";
2+
import { createRoot, Root } from 'react-dom/client';
33

44
import Utils from "../utils";
55
const utils = new Utils();
@@ -17,6 +17,8 @@ class SubmissionNotice {
1717

1818
noticeElement: HTMLDivElement;
1919

20+
root: Root;
21+
2022
constructor(contentContainer: ContentContainer, callback: () => unknown) {
2123
this.noticeRef = React.createRef();
2224

@@ -30,13 +32,13 @@ class SubmissionNotice {
3032

3133
referenceNode.prepend(this.noticeElement);
3234

33-
ReactDOM.render(
35+
this.root = createRoot(this.noticeElement);
36+
this.root.render(
3437
<SubmissionNoticeComponent
3538
contentContainer={contentContainer}
3639
callback={callback}
3740
ref={this.noticeRef}
38-
closeListener={() => this.close(false)} />,
39-
this.noticeElement
41+
closeListener={() => this.close(false)} />
4042
);
4143
}
4244

@@ -46,7 +48,7 @@ class SubmissionNotice {
4648

4749
close(callRef = true): void {
4850
if (callRef) this.noticeRef.current.cancel();
49-
ReactDOM.unmountComponentAtNode(this.noticeElement);
51+
this.root.unmount();
5052

5153
this.noticeElement.remove();
5254
}

src/render/Tooltip.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from "react";
2-
import * as ReactDOM from "react-dom";
2+
import { createRoot, Root } from 'react-dom/client';
33
import { ButtonListener } from "../types";
44

55
export interface TooltipProps {
@@ -26,6 +26,7 @@ export class Tooltip {
2626
container: HTMLDivElement;
2727

2828
timer: NodeJS.Timeout;
29+
root: Root;
2930

3031
constructor(props: TooltipProps) {
3132
props.bottomOffset ??= "70px";
@@ -54,8 +55,9 @@ export class Tooltip {
5455
}
5556

5657
const backgroundColor = `rgba(28, 28, 28, ${props.opacity})`;
57-
58-
ReactDOM.render(
58+
59+
this.root = createRoot(this.container);
60+
this.root.render(
5961
<div style={{bottom: props.bottomOffset, left: props.leftOffset, right: props.rightOffset, backgroundColor}}
6062
className={"sponsorBlockTooltip" + (props.displayTriangle ? " sbTriangle" : "") + ` ${props.extraClass}`}>
6163
<div>
@@ -93,8 +95,7 @@ export class Tooltip {
9395
{chrome.i18n.getMessage("GotIt")}
9496
</button>
9597
: null}
96-
</div>,
97-
this.container
98+
</div>
9899
)
99100
}
100101

@@ -120,7 +121,7 @@ export class Tooltip {
120121
}
121122

122123
close(): void {
123-
ReactDOM.unmountComponentAtNode(this.container);
124+
this.root.unmount();
124125
this.container.remove();
125126

126127
if (this.timer) clearTimeout(this.timer);

0 commit comments

Comments
 (0)