Skip to content

refactor: prepare react 19 types #4553

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions @types/canvas-iframe.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
declare namespace JSX {
interface IntrinsicElements {
iframe: React.DetailedHTMLProps<
React.IframeHTMLAttributes<HTMLIFrameElement> & {
credentialless?: "true";
},
HTMLIFrameElement
>;
declare namespace React {
interface IframeHTMLAttributes {
credentialless?: "true";
}
}
2 changes: 1 addition & 1 deletion apps/builder/app/auth/brand-button.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { css, textVariants, theme } from "@webstudio-is/design-system";
import type { ComponentProps } from "react";
import type { ComponentProps, JSX } from "react";

export const buttonStyle = css({
boxSizing: "border-box",
Expand Down
1 change: 1 addition & 0 deletions apps/builder/app/auth/login.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { JSX } from "react";
import type { StoryFn } from "@storybook/react";
import { createBrowserRouter, RouterProvider } from "react-router-dom";
import { Login } from "./login";
Expand Down
2 changes: 1 addition & 1 deletion apps/builder/app/builder/builder.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useMemo, useState, type ReactNode } from "react";
import { useEffect, useMemo, useState, type JSX, type ReactNode } from "react";
import { useStore } from "@nanostores/react";
import { TooltipProvider } from "@radix-ui/react-tooltip";
import { usePublish, $publisher } from "~/shared/pubsub";
Expand Down
2 changes: 1 addition & 1 deletion apps/builder/app/builder/features/address-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ const Suggestions = ({
options,
onSelect,
}: {
containerRef: RefObject<HTMLFormElement>;
containerRef: RefObject<null | HTMLFormElement>;
options: string[];
onSelect: (option: string) => void;
}) => {
Expand Down
2 changes: 1 addition & 1 deletion apps/builder/app/builder/features/ai/ai-command-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const AiCommandBar = () => {

const [isAudioTranscribing, setIsAudioTranscribing] = useState(false);
const [isAiRequesting, setIsAiRequesting] = useState(false);
const abortController = useRef<AbortController>();
const abortController = useRef<undefined | AbortController>(undefined);
const recordButtonRef = useRef<HTMLButtonElement>(null);
const guardIdRef = useRef(0);
const { enableCanvasPointerEvents, disableCanvasPointerEvents } =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type UseClickAndHoldProps = {
* - `onCancel`: Pointer up outside target during long press.
*/
export const useLongPressToggle = (props: UseClickAndHoldProps) => {
const currentTarget = useRef<Element>();
const currentTarget = useRef<undefined | Element>(undefined);
const pointerDownTimeRef = useRef(0);
const stateRef = useRef<"idle" | "active">("idle");
const keyMapRef = useRef(new Set<string>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const useMediaRecorder = (
},
options = DEFAULT_OPTIONS
) => {
const disposeRef = useRef<() => void>();
const disposeRef = useRef<undefined | (() => void)>(undefined);

const cancelRef = useRef(false);
const isActiveRef = useRef<boolean>(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { z } from "zod";
import { type FocusEventHandler, useState, useCallback } from "react";
import { type FocusEventHandler, useState, useCallback, type JSX } from "react";
import { useStore } from "@nanostores/react";
import { useDebouncedCallback } from "use-debounce";
import slugify from "slugify";
Expand Down
2 changes: 2 additions & 0 deletions apps/builder/app/builder/features/pages/form.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { JSX } from "react";

export const Form = ({
onSubmit,
children,
Expand Down
1 change: 1 addition & 0 deletions apps/builder/app/builder/features/pages/page-settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
useCallback,
useId,
useEffect,
type JSX,
} from "react";
import { useStore } from "@nanostores/react";
import { useDebouncedCallback } from "use-debounce";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { JSX } from "react";
import { createBrowserRouter, RouterProvider } from "react-router-dom";
import { ProjectSettingsView } from "./project-settings";
import { $pages } from "~/shared/nano-states";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ const VariablePanel = forwardRef<
VariablePanel.displayName = "VariablePanel";

const VariablePopoverContext = createContext<{
containerRef?: RefObject<HTMLElement>;
containerRef?: RefObject<null | HTMLElement>;
}>({});

export const VariablePopoverProvider = VariablePopoverContext.Provider;
Expand Down Expand Up @@ -627,7 +627,7 @@ export const VariablePopoverTrigger = forwardRef<
const { containerRef } = useContext(VariablePopoverContext);
const [triggerRef, sideOffsset] = useSideOffset({ isOpen, containerRef });
const bindingPopoverContainerRef = useRef<HTMLDivElement>(null);
const panelRef = useRef<undefined | PanelApi>();
const panelRef = useRef<undefined | PanelApi>(undefined);
const formRef = useRef<HTMLFormElement>(null);
const resources = useStore($resources);
const { allowDynamicData } = useStore($userPlanFeatures);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useState, type ReactNode } from "react";
import { useState, type JSX, type ReactNode } from "react";
import { declarationDescriptions } from "@webstudio-is/css-data";
import { AlertIcon } from "@webstudio-is/icons";
import {
Flex,
rawTheme,
Expand All @@ -19,7 +20,6 @@ import {
getPriorityStyleValueSource,
PropertyInfo,
} from "../../property-label";
import { AlertIcon } from "@webstudio-is/icons";

export const ToggleGroupTooltip = ({
isOpen,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState, type ReactNode } from "react";
import { useState, type JSX, type ReactNode } from "react";
import {
theme,
Box,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const useScrub = <P extends StyleProperty>(props: {
const nonDependencies = useRef({ props, values, properties });
nonDependencies.current = { props, values, properties };

const unitRef = useRef<UnitValue["unit"]>();
const unitRef = useRef<undefined | UnitValue["unit"]>(undefined);

useEffect(() => {
if (finalTarget === undefined) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ const useScrub = ({
onChangeComplete: (value: StyleValue) => void;
shouldHandleEvent?: (node: Node) => boolean;
}): [
React.MutableRefObject<HTMLDivElement | null>,
React.MutableRefObject<HTMLInputElement | null>,
React.RefObject<HTMLDivElement | null>,
React.RefObject<HTMLInputElement | null>,
] => {
const scrubRef = useRef<HTMLDivElement | null>(null);
const inputRef = useRef<HTMLInputElement | null>(null);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState, useMemo } from "react";
import { useState, useMemo, type JSX } from "react";
import * as SelectPrimitive from "@radix-ui/react-select";
import type { Unit } from "@webstudio-is/css-engine";
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
Select,
Grid,
} from "@webstudio-is/design-system";
import { useEffect, useState } from "react";
import { useEffect, useState, type JSX } from "react";
import {
CssValueInputContainer,
type IntermediateStyleValue,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useMemo } from "react";
import { useMemo, type JSX } from "react";
import type { RgbaColor } from "colord";
import {
toValue,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState } from "react";
import { useState, type JSX } from "react";
import { Flex, Button, Collapsible } from "@webstudio-is/design-system";
import {
ChevronFilledDownIcon,
Expand Down
4 changes: 2 additions & 2 deletions apps/builder/app/builder/features/workspace/canvas-iframe.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { forwardRef, useMemo, useRef, type RefObject } from "react";
import { forwardRef, useMemo, useRef, type JSX, type RefObject } from "react";
import {
css,
canvasPointerEventsPropertyName,
Expand Down Expand Up @@ -27,7 +27,7 @@ type CanvasIframeProps = JSX.IntrinsicElements["iframe"];
const CanvasRectUpdater = ({
iframeRef,
}: {
iframeRef: RefObject<HTMLIFrameElement>;
iframeRef: RefObject<null | HTMLIFrameElement>;
}) => {
const [updateCallback, setUpdateCallback] = useState<
undefined | (() => void)
Expand Down
8 changes: 7 additions & 1 deletion apps/builder/app/builder/shared/assets/assets-shell.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { useEffect, useRef, useState, type ComponentProps } from "react";
import {
useEffect,
useRef,
useState,
type ComponentProps,
type JSX,
} from "react";
import type { AssetType } from "@webstudio-is/asset-uploader";
import {
Flex,
Expand Down
4 changes: 2 additions & 2 deletions apps/builder/app/builder/shared/binding-popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const BindingPanel = ({
onChange: () => void;
onSave: (value: string, invalid: boolean) => void;
}) => {
const editorApiRef = useRef<undefined | EditorApi>();
const editorApiRef = useRef<undefined | EditorApi>(undefined);
const [expression, setExpression] = useState(value);
const usedIdentifiers = useMemo(
() => getExpressionIdentifiers(value),
Expand Down Expand Up @@ -335,7 +335,7 @@ const BindingButton = forwardRef<
BindingButton.displayName = "BindingButton";

const BindingPopoverContext = createContext<{
containerRef?: RefObject<HTMLElement>;
containerRef?: RefObject<null | HTMLElement>;
side?: "left" | "right";
}>({});

Expand Down
4 changes: 2 additions & 2 deletions apps/builder/app/builder/shared/code-editor-base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ export const EditorContent = ({
}: EditorContentProps) => {
globalStyles();

const editorRef = useRef<null | HTMLDivElement>(null);
const viewRef = useRef<undefined | EditorView>();
const editorRef = useRef<HTMLDivElement>(null);
const viewRef = useRef<undefined | EditorView>(undefined);

const onChangeRef = useRef(onChange);
onChangeRef.current = onChange;
Expand Down
12 changes: 6 additions & 6 deletions apps/builder/app/builder/shared/floating-panel.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {
type MutableRefObject,
type RefObject,
useContext,
useRef,
useState,
createContext,
useLayoutEffect,
type JSX,
} from "react";
import {
FloatingPanelPopover,
Expand All @@ -23,9 +23,9 @@ export const useSideOffset = ({
}: {
side?: "left" | "right";
isOpen: boolean;
containerRef?: RefObject<HTMLElement>;
}): [MutableRefObject<HTMLButtonElement | null>, number] => {
const triggerRef = useRef<HTMLButtonElement | null>(null);
containerRef?: RefObject<null | HTMLElement>;
}): [RefObject<HTMLButtonElement>, number] => {
const triggerRef = useRef<null | HTMLButtonElement>(null);
const [sideOffset, setSideOffset] = useState(0);

// use layout effect to avoid popover jumping
Expand Down Expand Up @@ -55,7 +55,7 @@ export const useSideOffset = ({
};

const FloatingPanelContext = createContext<{
container: RefObject<HTMLElement>;
container: RefObject<null | HTMLElement>;
}>({
container: {
current: null,
Expand All @@ -67,7 +67,7 @@ export const FloatingPanelProvider = ({
container,
}: {
children: JSX.Element;
container: RefObject<HTMLElement>;
container: RefObject<null | HTMLElement>;
}) => (
<FloatingPanelContext.Provider value={{ container }}>
{children}
Expand Down
4 changes: 2 additions & 2 deletions apps/builder/app/canvas/canvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ const useElementsTree = (

const DesignMode = () => {
const debounceEffect = useDebounceEffect();
const ref = useRef<Instances>();
const ref = useRef<undefined | Instances>(undefined);

useDragAndDrop();

Expand Down Expand Up @@ -182,7 +182,7 @@ const DesignMode = () => {

const ContentEditMode = () => {
const debounceEffect = useDebounceEffect();
const ref = useRef<Instances>();
const ref = useRef<undefined | Instances>(undefined);

useEffect(() => {
const abortController = new AbortController();
Expand Down
1 change: 1 addition & 0 deletions apps/builder/app/canvas/elements.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
Fragment,
type ForwardRefExoticComponent,
type JSX,
type RefAttributes,
type RefObject,
} from "react";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
useLayoutEffect,
useCallback,
useRef,
type JSX,
} from "react";
import {
KEY_ENTER_COMMAND,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
useMemo,
Fragment,
type ReactNode,
type JSX,
} from "react";
import { $getSelection, $isRangeSelection } from "lexical";
import { computed } from "nanostores";
Expand Down
2 changes: 1 addition & 1 deletion apps/builder/app/canvas/shared/use-pointer-outline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { Point } from "@webstudio-is/design-system";
// Draw a point where we think the pointer is to visualize if calculations are based on the right position
// Only needed for debugging.
export const usePointerOutline = () => {
const ref = useRef<HTMLDivElement>();
const ref = useRef<undefined | HTMLDivElement>(undefined);

useEffect(() => {
const div = document.createElement("div");
Expand Down
1 change: 1 addition & 0 deletions apps/builder/app/dashboard/dashboard.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { StoryFn } from "@storybook/react";
import type { JSX } from "react";
import { createBrowserRouter, RouterProvider } from "react-router-dom";
import { Dashboard } from "./dashboard";
import type { UserPlanFeatures } from "~/shared/db/user-plan-features.server";
Expand Down
2 changes: 1 addition & 1 deletion apps/builder/app/dashboard/projects/project-dialogs.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useRevalidator } from "@remix-run/react";
import { useEffect, useState } from "react";
import { useEffect, useState, type JSX } from "react";
import {
Box,
Button,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { JSX } from "react";
import { test, expect, describe, beforeEach } from "vitest";
import { nanoid } from "nanoid";
import {
Expand Down
1 change: 1 addition & 0 deletions apps/builder/app/shared/matcher.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { describe, expect, test, vi } from "vitest";
import type { JSX } from "react";
import { renderJsx, $, ExpressionValue } from "@webstudio-is/sdk/testing";
import { coreMetas } from "@webstudio-is/react-sdk";
import * as baseMetas from "@webstudio-is/sdk-components-react/metas";
Expand Down
4 changes: 3 additions & 1 deletion apps/builder/app/shared/pubsub/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ export const createPubsub = <PublishMap>() => {
* To publish a postMessage event on the iframe and parent window from the parent window.
*/
usePublish() {
const postMessageRef = useRef<typeof window.postMessage>();
const postMessageRef = useRef<undefined | typeof window.postMessage>(
undefined
);

const iframeRefCallback = useCallback(
(element: HTMLIFrameElement | null) => {
Expand Down
1 change: 1 addition & 0 deletions apps/builder/app/shared/style-object-model.test.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { JSX } from "react";
import { describe, expect, test } from "vitest";
import type { HtmlTags } from "html-tags";
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
type ComponentProps,
type FocusEvent,
forwardRef,
type JSX,
type KeyboardEvent,
} from "react";
import { Text } from "../text";
Expand Down
2 changes: 1 addition & 1 deletion packages/design-system/src/components/combobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ export const useCombobox = <Item,>({
...rest
}: UseComboboxProps<Item>) => {
const [isOpen, setIsOpen] = useState(false);
const selectedItemRef = useRef<Item>();
const selectedItemRef = useRef<undefined | Item>(undefined);
const itemsCache = useRef<Item[]>([]);
const [matchedItems, setMatchedItems] = useState<Item[]>([]);

Expand Down
2 changes: 1 addition & 1 deletion packages/design-system/src/components/component-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* https://www.figma.com/file/sfCE7iLS0k25qCxiifQNLE/%F0%9F%93%9A-Webstudio-Library?node-id=2608-8921
*/

import { forwardRef, type ComponentProps } from "react";
import { forwardRef, type ComponentProps, type JSX } from "react";
import { css, theme } from "../stitches.config";
import { textVariants } from "./text";
import { Tooltip } from "./tooltip";
Expand Down
Loading
Loading