Skip to content

Commit 3ab412a

Browse files
authored
fix: json parsing with inf/nan (#7309)
Fixes "Copy as JSON" when we have inf/nan
1 parent b8655d6 commit 3ab412a

File tree

4 files changed

+23
-15
lines changed

4 files changed

+23
-15
lines changed

‎frontend/src/components/data-table/download-actions.tsx‎

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import { useLocale } from "react-aria";
1212
import { logNever } from "@/utils/assertNever";
1313
import { copyToClipboard } from "@/utils/copy";
1414
import { downloadByURL } from "@/utils/download";
15-
import { jsonToTSV } from "@/utils/json/json-parser";
15+
import { prettyError } from "@/utils/errors";
16+
import { jsonParseWithSpecialChar, jsonToTSV } from "@/utils/json/json-parser";
1617
import { Button } from "../ui/button";
1718
import {
1819
DropdownMenu,
@@ -152,7 +153,17 @@ export const DownloadAs: React.FC<DownloadActionProps> = (props) => {
152153
{clipboardOptions.map((option) => (
153154
<DropdownMenuItem
154155
key={option.label}
155-
onSelect={() => handleClipboardCopy(option.format)}
156+
onSelect={async () => {
157+
try {
158+
await handleClipboardCopy(option.format);
159+
} catch (error) {
160+
toast({
161+
title: "Failed to copy to clipboard",
162+
description: prettyError(error),
163+
variant: "danger",
164+
});
165+
}
166+
}}
156167
>
157168
<option.icon className="mo-dropdown-icon" />
158169
<div className="flex flex-col">
@@ -171,12 +182,9 @@ export const DownloadAs: React.FC<DownloadActionProps> = (props) => {
171182
};
172183

173184
function fetchJson(url: string): Promise<Record<string, unknown>[]> {
174-
return fetch(url).then((res) => {
175-
if (!res.ok) {
176-
throw new Error(res.statusText);
177-
}
178-
return res.json();
179-
});
185+
return fetchText(url).then(
186+
jsonParseWithSpecialChar<Record<string, unknown>[]>,
187+
);
180188
}
181189

182190
function fetchText(url: string): Promise<string> {

‎frontend/src/components/data-table/row-viewer-panel/row-viewer.tsx‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { useRef, useState } from "react";
1818
import { useLocale } from "react-aria";
1919
import { ColumnName } from "@/components/datasources/components";
2020
import { CopyClipboardIcon } from "@/components/icons/copy-icon";
21+
import { Spinner } from "@/components/icons/spinner";
2122
import { KeyboardHotkeys } from "@/components/shortcuts/renderShortcut";
2223
import { Button } from "@/components/ui/button";
2324
import { Input } from "@/components/ui/input";
@@ -29,6 +30,7 @@ import {
2930
TableHeader,
3031
TableRow,
3132
} from "@/components/ui/table";
33+
import { DelayMount } from "@/components/utils/delay-mount";
3234
import { useAsyncData } from "@/hooks/useAsyncData";
3335
import { useKeydownOnElement } from "@/hooks/useHotkey";
3436
import { Banner, ErrorBanner } from "@/plugins/impl/common/error-banner";
@@ -136,11 +138,9 @@ export const RowViewerPanel: React.FC<RowViewerPanelProps> = ({
136138

137139
if (!rows) {
138140
return (
139-
<SimpleBanner
140-
kind="warn"
141-
Icon={AlertTriangle}
142-
message="No data available. Please report the issue."
143-
/>
141+
<DelayMount milliseconds={200}>
142+
<Spinner size="medium" centered={true} />
143+
</DelayMount>
144144
);
145145
}
146146

‎frontend/src/components/ui/table.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const Table = React.forwardRef<
77
HTMLTableElement,
88
React.HTMLAttributes<HTMLTableElement>
99
>(({ className, ...props }, ref) => (
10-
<div className="w-full overflow-auto flex-1">
10+
<div className="w-full overflow-auto scrollbar-thin flex-1">
1111
<table
1212
ref={ref}
1313
className={cn("w-full caption-bottom text-sm", className)}

‎frontend/src/core/websocket/useMarimoWebSocket.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ export function useMarimoWebSocket(opts: {
331331
try {
332332
handleMessage(e);
333333
} catch (error) {
334-
Logger.error("Failed to handle message", error);
334+
Logger.error("Failed to handle message", e.data, error);
335335
toast({
336336
title: "Failed to handle message",
337337
description: prettyError(error),

0 commit comments

Comments
 (0)