Skip to content

Commit a85b658

Browse files
authored
migrate to react 19 (#2272)
migrate to react 19 + fix lingering typescript errors and weirdness.
1 parent 515863b commit a85b658

29 files changed

Lines changed: 146 additions & 74 deletions

frontend/app/block/block.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function getViewElem(
6363
contentRef: React.RefObject<HTMLDivElement>,
6464
blockView: string,
6565
viewModel: ViewModel
66-
): JSX.Element {
66+
): React.ReactElement {
6767
if (isBlank(blockView)) {
6868
return <CenteredDiv>No View</CenteredDiv>;
6969
}

frontend/app/block/blockframe.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ function handleHeaderContextMenu(
8282
ContextMenuModel.showContextMenu(menu, e);
8383
}
8484

85-
function getViewIconElem(viewIconUnion: string | IconButtonDecl, blockData: Block): JSX.Element {
85+
function getViewIconElem(viewIconUnion: string | IconButtonDecl, blockData: Block): React.ReactElement {
8686
if (viewIconUnion == null || typeof viewIconUnion === "string") {
8787
const viewIcon = viewIconUnion as string;
8888
return <div className="block-frame-view-icon">{getBlockHeaderIcon(viewIcon, blockData)}</div>;
@@ -108,8 +108,8 @@ function computeEndIcons(
108108
viewModel: ViewModel,
109109
nodeModel: NodeModel,
110110
onContextMenu: (e: React.MouseEvent<HTMLDivElement>) => void
111-
): JSX.Element[] {
112-
const endIconsElem: JSX.Element[] = [];
111+
): React.ReactElement[] {
112+
const endIconsElem: React.ReactElement[] = [];
113113
const endIconButtons = util.useAtomValueSafe(viewModel?.endIconButtons);
114114
const magnified = jotai.useAtomValue(nodeModel.isMagnified);
115115
const ephemeral = jotai.useAtomValue(nodeModel.isEphemeral);
@@ -206,12 +206,12 @@ const BlockFrame_Header = ({
206206

207207
const endIconsElem = computeEndIcons(viewModel, nodeModel, onContextMenu);
208208
const viewIconElem = getViewIconElem(viewIconUnion, blockData);
209-
let preIconButtonElem: JSX.Element = null;
209+
let preIconButtonElem: React.ReactElement = null;
210210
if (preIconButton) {
211211
preIconButtonElem = <IconButton decl={preIconButton} className="block-frame-preicon-button" />;
212212
}
213213

214-
const headerTextElems: JSX.Element[] = [];
214+
const headerTextElems: React.ReactElement[] = [];
215215
if (typeof headerTextUnion === "string") {
216216
if (!util.isBlank(headerTextUnion)) {
217217
headerTextElems.push(
@@ -310,8 +310,8 @@ const HeaderTextElem = React.memo(({ elem, preview }: { elem: HeaderElem; previe
310310
return null;
311311
});
312312

313-
function renderHeaderElements(headerTextUnion: HeaderElem[], preview: boolean): JSX.Element[] {
314-
const headerTextElems: JSX.Element[] = [];
313+
function renderHeaderElements(headerTextUnion: HeaderElem[], preview: boolean): React.ReactElement[] {
314+
const headerTextElems: React.ReactElement[] = [];
315315
for (let idx = 0; idx < headerTextUnion.length; idx++) {
316316
const elem = headerTextUnion[idx];
317317
const renderedElement = <HeaderTextElem elem={elem} key={idx} preview={preview} />;
@@ -536,7 +536,7 @@ const BlockFrame_Default_Component = (props: BlockFrameProps) => {
536536
const magnifiedBlockBlur = jotai.useAtomValue(magnifiedBlockBlurAtom);
537537
const [magnifiedBlockOpacityAtom] = React.useState(() => getSettingsKeyAtom("window:magnifiedblockopacity"));
538538
const magnifiedBlockOpacity = jotai.useAtomValue(magnifiedBlockOpacityAtom);
539-
const connBtnRef = React.useRef<HTMLDivElement>();
539+
const connBtnRef = React.useRef<HTMLDivElement>(null);
540540
const noHeader = util.useAtomValueSafe(viewModel?.noHeader);
541541

542542
React.useEffect(() => {

frontend/app/element/button.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import "./button.scss";
99
interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
1010
className?: string;
1111
children?: ReactNode;
12-
as?: keyof JSX.IntrinsicElements | React.ComponentType<any>;
12+
as?: keyof React.JSX.IntrinsicElements | React.ComponentType<any>;
1313
}
1414

1515
const Button = memo(

frontend/app/element/copybutton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2025, Command Line Inc.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
import { clsx } from "clsx";
4+
import clsx from "clsx";
55
import { useEffect, useRef, useState } from "react";
66
import "./copybutton.scss";
77
import { IconButton } from "./iconbutton";

frontend/app/element/expandablemenu.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2025, Command Line
22
// SPDX-License-Identifier: Apache-2.0
33

4-
import { clsx } from "clsx";
4+
import clsx from "clsx";
55
import { atom, useAtom } from "jotai";
66
import { Children, ReactElement, ReactNode, cloneElement, isValidElement, useRef } from "react";
77

@@ -109,7 +109,7 @@ const ExpandableMenuItemGroup = ({
109109
const [openGroups, setOpenGroups] = useAtom(openGroupsAtom);
110110

111111
// Generate a unique ID for this group using useRef
112-
const idRef = useRef<string>();
112+
const idRef = useRef<string>(null);
113113

114114
if (!idRef.current) {
115115
// Generate a unique ID when the component is first rendered
@@ -146,10 +146,11 @@ const ExpandableMenuItemGroup = ({
146146

147147
const renderChildren = Children.map(children, (child: ReactElement) => {
148148
if (child && child.type === ExpandableMenuItemGroupTitle) {
149-
return cloneElement(child, {
150-
...child.props,
149+
const childProps = child.props as ExpandableMenuItemGroupTitleProps;
150+
return cloneElement(child as ReactElement<ExpandableMenuItemGroupTitleProps>, {
151+
...childProps,
151152
onClick: () => {
152-
child.props.onClick?.();
153+
childProps.onClick?.();
153154
toggleOpen();
154155
},
155156
});

frontend/app/element/flyoutmenu.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ export const CustomRenderer: Story = {
263263
</div>
264264
);
265265

266-
const renderMenu = (subMenu: JSX.Element) => <div>{subMenu}</div>;
266+
const renderMenu = (subMenu: React.ReactElement) => <div>{subMenu}</div>;
267267

268268
const modifiedArgs = {
269269
...args,

frontend/app/element/flyoutmenu.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ type MenuProps = {
1414
placement?: Placement;
1515
onOpenChange?: (isOpen: boolean) => void;
1616
children: ReactNode | ReactNode[];
17-
renderMenu?: (subMenu: JSX.Element, props: any) => JSX.Element;
18-
renderMenuItem?: (item: MenuItem, props: any) => JSX.Element;
17+
renderMenu?: (subMenu: React.ReactElement, props: any) => React.ReactElement;
18+
renderMenuItem?: (item: MenuItem, props: any) => React.ReactElement;
1919
};
2020

2121
const FlyoutMenuComponent = memo(
@@ -214,8 +214,8 @@ type SubMenuProps = {
214214
item: MenuItem
215215
) => void;
216216
handleOnClick: (e: React.MouseEvent<HTMLDivElement>, item: MenuItem) => void;
217-
renderMenu?: (subMenu: JSX.Element, props: any) => JSX.Element;
218-
renderMenuItem?: (item: MenuItem, props: any) => JSX.Element;
217+
renderMenu?: (subMenu: React.ReactElement, props: any) => React.ReactElement;
218+
renderMenuItem?: (item: MenuItem, props: any) => React.ReactElement;
219219
};
220220

221221
const SubMenu = memo(

frontend/app/element/linkbutton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2025, Command Line Inc.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
import { clsx } from "clsx";
4+
import clsx from "clsx";
55
import * as React from "react";
66

77
import "./linkbutton.scss";

frontend/app/element/markdown.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
transformBlocks,
1111
} from "@/app/element/markdown-util";
1212
import { boundNumber, useAtomValueSafe } from "@/util/util";
13-
import { clsx } from "clsx";
13+
import clsx from "clsx";
1414
import { Atom } from "jotai";
1515
import { OverlayScrollbarsComponent, OverlayScrollbarsComponentRef } from "overlayscrollbars-react";
1616
import { useEffect, useMemo, useRef, useState } from "react";

frontend/app/element/popover.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ interface PopoverButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElemen
120120
isActive?: boolean;
121121
children: React.ReactNode;
122122
getReferenceProps?: () => any;
123-
as?: keyof JSX.IntrinsicElements | React.ComponentType<any>;
123+
as?: keyof React.JSX.IntrinsicElements | React.ComponentType<any>;
124124
}
125125

126126
const PopoverButton = forwardRef<HTMLButtonElement | HTMLDivElement, PopoverButtonProps>(

0 commit comments

Comments
 (0)