Skip to content

Commit 45b95e7

Browse files
authored
Update to react 19 (placemark#233)
1 parent 05801e9 commit 45b95e7

27 files changed

Lines changed: 1884 additions & 1276 deletions

app/components/converter.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { getFilesFromDataTransferItems } from "@placemarkio/flat-drop-files";
21
import {
32
DownloadIcon,
43
FileTextIcon,
@@ -18,6 +17,7 @@ import {
1817
stringToGeoJSON,
1918
} from "app/lib/convert";
2019
import type { ConvertResult } from "app/lib/convert/utils";
20+
import { getFilesFromDataTransferItems } from "app/lib/flatDropFiles";
2121
import { newFeatureId } from "app/lib/id";
2222
import { lib } from "app/lib/worker";
2323
import { fileOpen, fileSave } from "browser-fs-access";

app/components/csv_options_form.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { QuestionMarkCircledIcon } from "@radix-ui/react-icons";
2+
import { useSuspenseQuery } from "@tanstack/react-query";
23
import { SelectHeader } from "app/components/csv_options_form/select_header";
34
import { MAX_GEOCODER_ROWS } from "app/lib/constants";
45
import type { ImportOptions } from "app/lib/convert";
@@ -10,7 +11,6 @@ import { Field, type FormikContextType, useFormikContext } from "formik";
1011
import { captureException } from "integrations/errors";
1112
import { useAtomValue } from "jotai";
1213
import { useEffect, useState } from "react";
13-
import { useQuery } from "react-query";
1414
import { dataAtom } from "state/jotai";
1515
import type { JsonObject } from "type-fest";
1616
import type { WorkBook } from "xlsx";
@@ -425,8 +425,9 @@ interface XlsOptionsFormProps {
425425
}
426426

427427
export function XlsOptionsForm(props: XlsOptionsFormProps) {
428-
const { data: xlsx } = useQuery("xlsx", async () => import("xlsx"), {
429-
suspense: true,
428+
const { data: xlsx } = useSuspenseQuery({
429+
queryKey: ["xlsx"],
430+
queryFn: async () => import("xlsx"),
430431
});
431432

432433
return <XlsOptionsFormInner {...props} xlsx={xlsx!} />;

app/components/dialogs/import_example.tsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { ClipboardIcon, DownloadIcon } from "@radix-ui/react-icons";
2+
import { useSuspenseQuery } from "@tanstack/react-query";
23
import { DialogHeader } from "app/components/dialog";
34
import { styledInlineA, TextWell } from "app/components/elements";
45
import { useImportString } from "app/hooks/use_import";
56
import { DEFAULT_IMPORT_OPTIONS } from "app/lib/convert";
67
import toast from "react-hot-toast";
7-
import { useQuery as useReactQuery } from "react-query";
88
import { z } from "zod";
99

1010
const ExampleList = z.array(z.string());
@@ -22,18 +22,15 @@ function friendlyName(filename: string): string {
2222

2323
export function ImportExampleDialog({ onClose }: { onClose: () => void }) {
2424
const doImport = useImportString();
25-
const { data: exampleList } = useReactQuery(
26-
"import-examples",
27-
() =>
25+
const { data: exampleList } = useSuspenseQuery({
26+
queryKey: ["import-examples"],
27+
queryFn: () =>
2828
fetch("https://data-library.placemark.io/")
2929
.then((r) => r.json())
3030
.then((json) => {
3131
return ExampleList.parse(json);
3232
}),
33-
{
34-
suspense: true,
35-
},
36-
);
33+
});
3734

3835
return (
3936
<>

app/components/dialogs/quickswitcher.tsx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Combobox } from "@headlessui/react";
22
import { ArrowDownIcon } from "@radix-ui/react-icons";
3+
import { useQuery } from "@tanstack/react-query";
34
import { useActions } from "app/components/context_actions/geometry_actions";
45
import { useMultiActions } from "app/components/context_actions/multi_actions";
56
import {
@@ -21,7 +22,6 @@ import Fuse from "fuse.js";
2122
import { useAtom, useAtomValue, useSetAtom } from "jotai";
2223
import { LngLatBounds, type LngLatLike } from "mapbox-gl";
2324
import { useContext, useMemo, useState } from "react";
24-
import { useQuery } from "react-query";
2525
import { USelection } from "state";
2626
import {
2727
dataAtom,
@@ -81,9 +81,9 @@ export function QuickswitcherDialog({ onClose }: { onClose: () => void }) {
8181
data: list,
8282
isLoading,
8383
isError,
84-
} = useQuery(
85-
["geocoder", query],
86-
async ({ signal }) => {
84+
} = useQuery({
85+
queryKey: ["geocoder", query],
86+
queryFn: async ({ signal }) => {
8787
return geocodeEarth({
8888
query: query || "",
8989
center: map?.map.getCenter(),
@@ -93,11 +93,9 @@ export function QuickswitcherDialog({ onClose }: { onClose: () => void }) {
9393
actions: actions.concat(multiActions).concat(singleActions),
9494
});
9595
},
96-
{
97-
enabled: query.length > 2,
98-
keepPreviousData: true,
99-
},
100-
);
96+
enabled: query.length > 2,
97+
placeholderData: (previousData, _previousQuery) => previousData,
98+
});
10199

102100
function goToFeature(item: QItem) {
103101
if (!item || !map) return;

app/components/drop.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getFilesFromDataTransferItems } from "@placemarkio/flat-drop-files";
1+
import { getFilesFromDataTransferItems } from "app/lib/flatDropFiles";
22
import { groupFiles } from "app/lib/group_files";
33
import type { FileWithHandle } from "browser-fs-access";
44
import { captureException } from "integrations/errors";

app/components/last_search_result.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ export function LastSearchResult() {
9090
<Button
9191
type="button"
9292
variant="primary"
93-
onClick={(e) => {
93+
// TODO: this should have a correct type, but classed-components
94+
// is not updated for React 19
95+
onClick={(e: React.MouseEvent) => {
9496
onAddPolygon(asPolygon);
9597
e.stopPropagation();
9698
}}
@@ -119,7 +121,7 @@ export function LastSearchResult() {
119121
<Button
120122
type="button"
121123
variant="primary"
122-
onClick={(e) => {
124+
onClick={(e: React.MouseEvent) => {
123125
e.stopPropagation();
124126
onAddPolygon(asPolygon);
125127
}}

app/components/layers/popover.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
PlusIcon,
3030
TrashIcon,
3131
} from "@radix-ui/react-icons";
32+
import { useQuery } from "@tanstack/react-query";
3233
import * as E from "app/components/elements";
3334
import { TextWell } from "app/components/elements";
3435
import { FORM_ERROR, Form } from "app/core/components/Form";
@@ -48,7 +49,6 @@ import { Maybe } from "purify-ts/Maybe";
4849
import { Popover as P, Tooltip as T } from "radix-ui";
4950
import { Suspense, useState } from "react";
5051
import toast from "react-hot-toast";
51-
import { useQuery as reactUseQuery } from "react-query";
5252
import { layerConfigAtom } from "state/jotai";
5353
import { match } from "ts-pattern";
5454
import { type ILayerConfig, zLayerConfig } from "types";
@@ -590,11 +590,12 @@ function SortableLayerConfig({ layerConfig }: { layerConfig: ILayerConfig }) {
590590
const transact = rep.useTransact();
591591
const [editing, setEditing] = useState<boolean>(false);
592592

593-
const { data: tilejson, isError } = reactUseQuery(
594-
layerConfig.url,
595-
async () => layerConfig.type === "TILEJSON" && getTileJSON(layerConfig.url),
596-
{ suspense: false, retry: false },
597-
);
593+
const { data: tilejson, isError } = useQuery({
594+
queryKey: [layerConfig.url],
595+
queryFn: async () =>
596+
layerConfig.type === "TILEJSON" && getTileJSON(layerConfig.url),
597+
retry: false,
598+
});
598599

599600
const style = {
600601
transform: CSS.Transform.toString(transform),

app/components/map_component.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export const MapComponent = memo(function MapComponent({
101101

102102
const dragTargetRef: React.MutableRefObject<DragTarget | null> =
103103
useRef<DragTarget>(null);
104-
const mapHandlers = useRef<PMapHandlers>();
104+
const mapHandlers = useRef<PMapHandlers>(null);
105105

106106
// Context
107107
const map = useContext(MapContext);

app/components/panels/feature_editor/feature_editor_folder.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
SortableContext,
1616
verticalListSortingStrategy,
1717
} from "@dnd-kit/sortable";
18+
import { useVirtualizer } from "@tanstack/react-virtual";
1819
import { LEFT_PANEL_ROW_HEIGHT } from "app/lib/constants";
1920
import { usePersistence } from "app/lib/persistence/context";
2021
import { generateKeyBetween, generateNKeysBetween } from "fractional-indexing";
@@ -23,7 +24,6 @@ import { useAtomValue } from "jotai";
2324
import isEqual from "lodash/isEqual";
2425
import { Portal } from "radix-ui";
2526
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
26-
import { useVirtual } from "react-virtual";
2727
import { USelection } from "state";
2828
import { dataAtom, type Sel, splitsAtom } from "state/jotai";
2929
import type { FolderMap } from "types";
@@ -255,9 +255,9 @@ export function FeatureEditorFolderInner() {
255255
return tree.findIndex(({ id }) => id === activeId);
256256
}, [tree, activeId]);
257257

258-
const rowVirtualizer = useVirtual({
259-
size: tree.length,
260-
parentRef,
258+
const rowVirtualizer = useVirtualizer({
259+
count: tree.length,
260+
getScrollElement: () => parentRef.current,
261261
estimateSize: useCallback(
262262
(index: number) => {
263263
return index === activeItemIndex ? 0 : LEFT_PANEL_ROW_HEIGHT;
@@ -479,10 +479,10 @@ export function FeatureEditorFolderInner() {
479479
className="relative w-full"
480480
style={{
481481
willChange: "transform",
482-
height: `${rowVirtualizer.totalSize}px`,
482+
height: `${rowVirtualizer.getTotalSize()}px`,
483483
}}
484484
>
485-
{rowVirtualizer.virtualItems.map((row) => {
485+
{rowVirtualizer.getVirtualItems().map((row) => {
486486
const item = tree[row.index];
487487
const isDragging = activeId === item.id;
488488
if (isDragging && dropIntoFolder) {

app/components/panels/feature_editor/feature_editor_folder/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { VirtualItem } from "react-virtual";
1+
import type { VirtualItem } from "@tanstack/react-virtual";
22

33
/**
44
* Helper to create style for a virtual element.

0 commit comments

Comments
 (0)