From 0f7795f1ea5bc2822e3a9d803056857da2fabaef Mon Sep 17 00:00:00 2001 From: Jan Potoms <2109932+Janpot@users.noreply.github.com> Date: Tue, 28 Nov 2023 11:23:07 +0100 Subject: [PATCH] Fix crash when function result type contains a constructor property (#2941) Signed-off-by: Jan Potoms <2109932+Janpot@users.noreply.github.com> --- packages/toolpad-app/package.json | 2 +- packages/toolpad-app/src/rpcClient.ts | 4 ++-- packages/toolpad-app/src/server/rpc.ts | 2 +- renovate.json | 5 +++++ .../fixture/toolpad/resources/functions.ts | 12 ++++++++++++ yarn.lock | 8 ++++---- 6 files changed, 25 insertions(+), 8 deletions(-) diff --git a/packages/toolpad-app/package.json b/packages/toolpad-app/package.json index c5681a8aeff..67b5bf9f82c 100644 --- a/packages/toolpad-app/package.json +++ b/packages/toolpad-app/package.json @@ -125,7 +125,7 @@ "recharts": "2.10.1", "semver": "7.5.4", "serialize-javascript": "6.0.1", - "superjson": "2.2.1", + "superjson": "2.0.0", "typescript": "5.3.2", "vite": "5.0.2", "vm-browserify": "1.1.2", diff --git a/packages/toolpad-app/src/rpcClient.ts b/packages/toolpad-app/src/rpcClient.ts index d2158c9c48b..bbab65275a5 100644 --- a/packages/toolpad-app/src/rpcClient.ts +++ b/packages/toolpad-app/src/rpcClient.ts @@ -1,4 +1,4 @@ -import { parse as superjsonParse } from 'superjson'; +import * as superjson from 'superjson'; import invariant from 'invariant'; import { QueryClient, @@ -41,7 +41,7 @@ function createRpcClient(endpoint: string | URL): Met } throw toolpadError; } - return superjsonParse(response.result); + return superjson.parse(response.result); } throw new Error(`HTTP ${res.status}`); diff --git a/packages/toolpad-app/src/server/rpc.ts b/packages/toolpad-app/src/server/rpc.ts index 4133d19c3ec..397c4fa5b3c 100644 --- a/packages/toolpad-app/src/server/rpc.ts +++ b/packages/toolpad-app/src/server/rpc.ts @@ -1,5 +1,5 @@ import type { IncomingMessage, ServerResponse } from 'http'; -import superjson from 'superjson'; +import * as superjson from 'superjson'; import express from 'express'; import * as z from 'zod'; import { fromZodError } from 'zod-validation-error'; diff --git a/renovate.json b/renovate.json index cb707399830..a2cffbfaf1c 100644 --- a/renovate.json +++ b/renovate.json @@ -73,6 +73,11 @@ "allowedVersions": "<= 13.4.19", "description": "https://github.com/mui/mui-toolpad/pull/2739" }, + { + "groupName": "superjson", + "matchPackageNames": ["superjson"], + "description": "they added a feature that breaks our app: https://github.com/blitz-js/superjson/pull/267. See https://github.com/blitz-js/superjson/issues/279" + }, { "matchDepTypes": ["action"], "pinDigests": true diff --git a/test/integration/backend-basic/fixture/toolpad/resources/functions.ts b/test/integration/backend-basic/fixture/toolpad/resources/functions.ts index f2a75bc4867..b5902eda288 100644 --- a/test/integration/backend-basic/fixture/toolpad/resources/functions.ts +++ b/test/integration/backend-basic/fixture/toolpad/resources/functions.ts @@ -145,3 +145,15 @@ export async function someNonJson() { regexp: /foo/i, }; } + +export interface RowDataPacket { + constructor: { + name: 'RowDataPacket'; + }; + [column: string]: any; + [column: number]: any; +} + +export async function mysqlResult(): Promise { + return []; +} diff --git a/yarn.lock b/yarn.lock index 6fc2eff761e..d7d8650035a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11759,10 +11759,10 @@ sucrase@^3.20.3, sucrase@^3.21.0: pirates "^4.0.1" ts-interface-checker "^0.1.9" -superjson@2.2.1: - version "2.2.1" - resolved "https://registry.yarnpkg.com/superjson/-/superjson-2.2.1.tgz#9377a7fa80fedb10c851c9dbffd942d4bcf79733" - integrity sha512-8iGv75BYOa0xRJHK5vRLEjE2H/i4lulTjzpUXic3Eg8akftYjkmQDa8JARQ42rlczXyFR3IeRoeFCc7RxHsYZA== +superjson@2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/superjson/-/superjson-2.0.0.tgz#7abcbe6c1badc2e689ea62c375ca257666a68282" + integrity sha512-W3n+NJ7TFjaLle8ihIIvsr/bbuKpnxeatsyjmhy7iSkom+/cshaHziCQAWXrHGWJVQSQFDOuES6C3nSEvcbrQg== dependencies: copy-anything "^3.0.2"