Skip to content

Commit

Permalink
fix: react 19 type error
Browse files Browse the repository at this point in the history
  • Loading branch information
YumoImer committed Dec 30, 2024
1 parent eb3315a commit 1f0bdc5
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .dumi/components/SemanticPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const SemanticPreview: React.FC<SemanticPreviewProps> = (props) => {
// ======================== Hover =========================
const containerRef = React.useRef<HTMLDivElement>(null);

const timerRef = React.useRef<ReturnType<typeof setTimeout>>();
const timerRef = React.useRef<ReturnType<typeof setTimeout>>(null);

const [positionMotion, setPositionMotion] = React.useState<boolean>(false);
const [hoverSemantic, setHoverSemantic] = React.useState<string | null>(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ const ComponentChangelog: React.FC<Readonly<React.PropsWithChildren>> = (props)
return (
<>
{isValidElement(children) &&
cloneElement(children as React.ReactElement, {
cloneElement(children as React.ReactElement<any>, {
onClick: () => setShow(true),
})}
<Drawer
Expand Down
4 changes: 2 additions & 2 deletions .dumi/theme/common/PrevAndNext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ const PrevAndNext: React.FC<{ rtl?: boolean }> = ({ rtl }) => {
return (
<section className={styles.prevNextNav}>
{prev &&
React.cloneElement(prev.label as ReactElement, {
React.cloneElement(prev.label as ReactElement<any>, {
className: classNames(styles.pageNav, styles.prevNav, prev.className),
})}
{next &&
React.cloneElement(next.label as ReactElement, {
React.cloneElement(next.label as ReactElement<any>, {
className: classNames(styles.pageNav, styles.nextNav, next.className),
})}
</section>
Expand Down
8 changes: 6 additions & 2 deletions .dumi/theme/layouts/DocLayout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const DocLayout: React.FC = () => {
const location = useLocation();
const { pathname, search, hash } = location;
const [locale, lang] = useLocale(locales);
const timerRef = useRef<ReturnType<typeof setTimeout>>();
const timerRef = useRef<ReturnType<typeof setTimeout>>(null);
const { direction } = useContext(SiteContext);
const { loading } = useSiteData();

Expand All @@ -52,7 +52,11 @@ const DocLayout: React.FC = () => {
timerRef.current = setTimeout(() => {
nprogressHiddenStyle?.remove();
}, 0);
return () => clearTimeout(timerRef.current);
return () => {
if (timerRef.current) {
clearTimeout(timerRef.current);
}
};
}, []);

// handle hash change or visit page hash from Link component, and jump after async chunk loaded
Expand Down
3 changes: 1 addition & 2 deletions components/attachments/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ function Attachments(props: AttachmentsProps, ref: React.Ref<AttachmentsRef>) {
React.useImperativeHandle(ref, () => ({
nativeElement: containerRef.current,
upload: (file) => {
const fileInput =
uploadRef.current?.nativeElement?.querySelector<HTMLInputElement>('input[type="file"]');
const fileInput = uploadRef.current?.nativeElement?.querySelector('input[type="file"]');

Check warning on line 93 in components/attachments/index.tsx

View check run for this annotation

Codecov / codecov/patch

components/attachments/index.tsx#L93

Added line #L93 was not covered by tests

// Trigger native change event
if (fileInput) {
Expand Down
9 changes: 5 additions & 4 deletions components/sender/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ import useStyle from './style';
import useSpeech, { type AllowSpeech } from './useSpeech';

import type { InputRef as AntdInputRef, ButtonProps, GetProps } from 'antd';
import type { CustomizeComponent, SubmitType } from './interface';

export type SubmitType = 'enter' | 'shiftEnter' | false;

type TextareaProps = GetProps<typeof Input.TextArea>;

export interface SenderComponents {
input?: CustomizeComponent<TextareaProps>;
input?: React.ComponentType<TextareaProps>;
}

export type ActionsRender = (
Expand Down Expand Up @@ -80,8 +81,8 @@ export type SenderRef = {
function getComponent<T>(
components: SenderComponents | undefined,
path: string[],
defaultComponent: CustomizeComponent<T>,
): CustomizeComponent<T> {
defaultComponent: React.ComponentType<T>,
): React.ComponentType<T> {
return getValue(components, path) || defaultComponent;
}

Expand Down
9 changes: 0 additions & 9 deletions components/sender/interface.ts

This file was deleted.

7 changes: 0 additions & 7 deletions components/suggestion/interface.ts

This file was deleted.

2 changes: 1 addition & 1 deletion tests/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const sleep = async (timeout = 0) => {
const customRender = (ui: ReactElement, options?: Omit<RenderOptions, 'wrapper'>): RenderResult =>
render(ui, { wrapper: StrictMode, ...options });

export function renderHook<T>(func: () => T): { result: React.RefObject<T> } {
export function renderHook<T>(func: () => T): { result: React.RefObject<T | null> } {
const result = createRef<T>();

const Demo: React.FC = () => {
Expand Down

0 comments on commit 1f0bdc5

Please sign in to comment.