From ba8df261c80d6fb33c2a158899a700ec33246394 Mon Sep 17 00:00:00 2001 From: Benjie Gillam Date: Wed, 4 Dec 2024 19:55:32 +0000 Subject: [PATCH 1/3] Fix Grafast playground by avoiding accessing 'process' in graphile-config --- grafast/website/package.json | 3 +- .../src/components/Playground/index.jsx | 56 +++++++++++++++---- utils/graphile-config/src/hooks.ts | 3 +- yarn.lock | 12 ++++ 4 files changed, 62 insertions(+), 12 deletions(-) diff --git a/grafast/website/package.json b/grafast/website/package.json index 04dfb6a29e..db10bbbe2b 100644 --- a/grafast/website/package.json +++ b/grafast/website/package.json @@ -28,7 +28,8 @@ "grafast": "workspace:^", "prism-react-renderer": "^2.0.6", "react": "^18.2.0", - "react-dom": "^18.2.0" + "react-dom": "^18.2.0", + "react-error-boundary": "^4.1.2" }, "devDependencies": { "@docusaurus/module-type-aliases": "2.4.1", diff --git a/grafast/website/src/components/Playground/index.jsx b/grafast/website/src/components/Playground/index.jsx index 7c90f3d1f0..f10106f9b8 100644 --- a/grafast/website/src/components/Playground/index.jsx +++ b/grafast/website/src/components/Playground/index.jsx @@ -1,21 +1,57 @@ import BrowserOnly from "@docusaurus/BrowserOnly"; import Head from "@docusaurus/Head"; import React from "react"; +import { ErrorBoundary } from "react-error-boundary"; export default function Playground() { return ( - - {() => { - const PlaygroundInner = require("./PlaygroundInner").default; + { + console.dir(error); + const issueStack = (error?.stack ?? error) + ?.split("\n") + .slice(0, 2) + .map((s) => s.trim()) + .join(" / "); return ( - <> - - - - - +
+

Something went wrong

+

+ Sorry about this. Grafast isn't really intended for usage on the + web and we seem to break the playground quite frequently as a + consequence. Please{" "} + + + open an issue + + + . +

+

Details:

+
+              {String(error?.stack ?? error)}
+            
+
); }} -
+ > + + {() => { + const PlaygroundInner = require("./PlaygroundInner").default; + return ( + <> + + + + + + ); + }} + + ); } diff --git a/utils/graphile-config/src/hooks.ts b/utils/graphile-config/src/hooks.ts index c78e5b971e..109a58502d 100644 --- a/utils/graphile-config/src/hooks.ts +++ b/utils/graphile-config/src/hooks.ts @@ -7,7 +7,8 @@ import type { UnwrapCallback, } from "./interfaces.js"; -const isDev = process.env.GRAPHILE_ENV === "development"; +const isDev = + typeof process !== "undefined" && process.env.GRAPHILE_ENV === "development"; export class AsyncHooks> { callbacks: { diff --git a/yarn.lock b/yarn.lock index 2794c2becf..9bf846ab99 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3962,6 +3962,7 @@ __metadata: prism-react-renderer: "npm:^2.0.6" react: "npm:^18.2.0" react-dom: "npm:^18.2.0" + react-error-boundary: "npm:^4.1.2" sqlite3: "npm:^5.1.6" languageName: unknown linkType: soft @@ -18294,6 +18295,17 @@ __metadata: languageName: node linkType: hard +"react-error-boundary@npm:^4.1.2": + version: 4.1.2 + resolution: "react-error-boundary@npm:4.1.2" + dependencies: + "@babel/runtime": "npm:^7.12.5" + peerDependencies: + react: ">=16.13.1" + checksum: b0adb5de94acfe625a1ff62b55ce9b3f0b5e486f1ce17132ebe4486ee14082917fe28a24c69b57a758cd487e1a8eb41ffbf15e1349a8fbb544cf85ba5d6149f5 + languageName: node + linkType: hard + "react-error-overlay@npm:^6.0.11": version: 6.0.11 resolution: "react-error-overlay@npm:6.0.11" From 7580bc16a050fd8d916c6dabe9d1ded980090349 Mon Sep 17 00:00:00 2001 From: Benjie Gillam Date: Wed, 4 Dec 2024 19:55:57 +0000 Subject: [PATCH 2/3] docs(changeset): Check that `process` exists before reading from it. --- .changeset/chatty-nails-poke.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/chatty-nails-poke.md diff --git a/.changeset/chatty-nails-poke.md b/.changeset/chatty-nails-poke.md new file mode 100644 index 0000000000..3424adcb96 --- /dev/null +++ b/.changeset/chatty-nails-poke.md @@ -0,0 +1,5 @@ +--- +"graphile-config": patch +--- + +Check that `process` exists before reading from it. From 4075e456466c9df72615c262a1928947ae010594 Mon Sep 17 00:00:00 2001 From: Benjie Gillam Date: Fri, 6 Dec 2024 09:41:37 +0000 Subject: [PATCH 3/3] Lint --- grafast/website/src/components/Playground/index.jsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/grafast/website/src/components/Playground/index.jsx b/grafast/website/src/components/Playground/index.jsx index f10106f9b8..ccb9581a97 100644 --- a/grafast/website/src/components/Playground/index.jsx +++ b/grafast/website/src/components/Playground/index.jsx @@ -17,9 +17,9 @@ export default function Playground() {

Something went wrong

- Sorry about this. Grafast isn't really intended for usage on the - web and we seem to break the playground quite frequently as a - consequence. Please{" "} + Sorry about this. Grafast isn't really intended for usage on + the web yet and we seem to break the playground quite frequently + as a consequence. Please{" "}