Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

feat: use edge runtime in developers site

Brad Barbinc7ff56b2f2e0
diff --git a/.vscode/remix.code-snippets b/.vscode/remix.code-snippets
index c29d19b75d..ae1fe9c095 100644
--- a/.vscode/remix.code-snippets
+++ b/.vscode/remix.code-snippets
@@ -2,7 +2,7 @@
"loader": {
"prefix": "/loader",
"body": [
- "import type { LoaderFunctionArgs } from \"@remix-run/node\"",
+ "import type { LoaderFunctionArgs } from \"@vercel/remix\"",
"",
"export async function loader({ request }: LoaderFunctionArgs) {",
" return null",
@@ -12,7 +12,7 @@
"action": {
"prefix": "/action",
"body": [
- "import type { ActionFunctionArgs } from \"@remix-run/node\"",
+ "import type { ActionFunctionArgs } from \"@vercel/remix\"",
"",
"export async function action({ request }: ActionFunctionArgs) {",
" return null",
@@ -34,7 +34,7 @@
"headers": {
"prefix": "/headers",
"body": [
- "import type { HeadersFunction } from '@remix-run/node'",
+ "import type { HeadersFunction } from '@vercel/remix'",
"",
"export const headers: HeadersFunction = ({ loaderHeaders }) => ({",
" 'Cache-Control': loaderHeaders.get('Cache-Control') ?? '',",
@@ -44,7 +44,7 @@
"links": {
"prefix": "/links",
"body": [
- "import type { LinksFunction } from '@remix-run/node'",
+ "import type { LinksFunction } from '@vercel/remix'",
"",
"export const links: LinksFunction = () => {",
" return []",
@@ -54,7 +54,7 @@
"meta": {
"prefix": "/meta",
"body": [
- "import type { MetaFunction } from '@remix-run/node'",
+ "import type { MetaFunction } from '@vercel/remix'",
"",
"export const meta: MetaFunction<typeof loader> = ({ data }) => [{",
" title: 'Title',",
diff --git a/apps/carbon/app/root.tsx b/apps/carbon/app/root.tsx
index f7d978a879..8d5f9219cc 100644
--- a/apps/carbon/app/root.tsx
+++ b/apps/carbon/app/root.tsx
@@ -28,6 +28,8 @@ import { useMode } from "./hooks/useMode";
import { getSessionFlash } from "./services/session.server";
import { modeValidator } from "./types/validators";
+export const config = { runtime: "edge" };
+
export function links() {
return [
{ rel: "stylesheet", href: Tailwind },
@@ -37,8 +39,6 @@ export function links() {
];
}
-export const config = { runtime: "edge" };
-
export const meta: MetaFunction = () => {
return [
{
diff --git a/apps/carbon/app/utils/installGlobals.ts b/apps/carbon/app/utils/installGlobals.ts
deleted file mode 100644
index 20581f6725..0000000000
--- a/apps/carbon/app/utils/installGlobals.ts
+++ /dev/null
@@ -1,114 +0,0 @@
-import { installGlobals } from "@remix-run/node";
-import { IncomingMessage } from "node:http";
-
-export function installAndLockGlobals() {
- // @ts-ignore
- if (global.__installedAndLocked) {
- return;
- }
-
- installGlobals({ nativeFetch: true });
-
- const File = global.File;
- const Headers = global.Headers;
- const Request = global.Request;
- const Response = global.Response;
- const fetch = global.fetch;
- const FormData = global.FormData;
-
- /* @vercel/remix expects the non-native Headers API
- see: https://github.com/vercel/remix/blob/325c03d4c395b3c48aee88b1574c4688ee59251e/packages/vercel-remix/server.ts#L105
- This adds a minimal compatibility layer, though the result is different
- when multiple values for the same header are added.
- {
- "header": [
- "value1, value2"
- ]
- }
- vs
- {
- "header": [
- "value1",
- "value2"
- ]
- }
- This should be fine, but hasn't been extensively tested.
- Need to patch the prototype here since undici holds a reference.
- */
- if (!Object.hasOwn(Headers.prototype, "raw")) {
- Object.defineProperties(Headers.prototype, {
- raw: {
- value: function raw() {
- const entries: Iterable<[string, string]> = this.entries();
- return Object.fromEntries(
- Array.from(entries).map(([k, v]) => [k, [v]])
- );
- },
- configurable: true,
- },
- });
- }
-
- /* @vercel/remix doesn't set duplex when initializing a steaming body
- see: https://github.com/vercel/remix/blob/325c03d4c395b3c48aee88b1574c4688ee59251e/packages/vercel-remix/server.ts#L83-L94
- */
- class PatchedRequest extends Request {
- constructor(input: RequestInfo | URL, init: RequestInit = {}) {
- let initPatched = init;
- if (
- init.body &&
- init.body instanceof IncomingMessage &&
- init.duplex === undefined
- ) {
- initPatched = {
- ...init,
- duplex: "half",
- };
- }
- super(input, initPatched);
- }
- }
-
- // Ignore future changes to these properties
- Object.defineProperties(global, {
- File: {
- get() {
- return File;
- },
- set() {},
- },
- Headers: {
- get() {
- return Headers;
- },
- set() {},
- },
- Request: {
- get() {
- return PatchedRequest;
- },
- set() {},
- },
- Response: {
- get() {
- return Response;
- },
- set() {},
- },
- fetch: {
- get() {
- return fetch;
- },
- set() {},
- },
- FormData: {
- get() {
- return FormData;
- },
- set() {},
- },
- });
-
- // @ts-ignore
- global.__installedAndLocked = true;
-}
diff --git a/apps/developers/app/entry.server.tsx b/apps/developers/app/entry.server.tsx
index 82984599e8..0cb74d5a84 100644
--- a/apps/developers/app/entry.server.tsx
+++ b/apps/developers/app/entry.server.tsx
@@ -1,22 +1,13 @@
import type { OperatingSystemPlatform } from "@carbon/react";
import { OperatingSystemContextProvider } from "@carbon/react";
import { I18nProvider } from "@react-aria/i18n";
-import { createReadableStreamFromReadable } from "@remix-run/node"; // or cloudflare/deno
import { RemixServer } from "@remix-run/react";
-import type { EntryContext, LoaderFunctionArgs } from "@vercel/remix";
-import { parseAcceptLanguage } from "intl-parse-accept-language";
-import isbot from "isbot";
-import { renderToPipeableStream } from "react-dom/server";
-import { PassThrough } from "stream";
-import logger from "~/lib/logger";
-import { installAndLockGlobals } from "./utils/installGlobals";
-
-const ABORT_DELAY = 30000;
+import type { EntryContext } from "@vercel/remix";
+import { handleRequest } from "@vercel/remix";
-// Workaround for vite single fetch mode
-installAndLockGlobals();
+import { parseAcceptLanguage } from "intl-parse-accept-language";
-export default function handleRequest(
+export default async function (
request: Request,
responseStatusCode: number,
responseHeaders: Headers,
@@ -33,146 +24,17 @@ export default function handleRequest(
?.includes("Mac")
? "mac"
: "windows";
-
- // If the request is from a bot, we want to wait for the full
- // response to render before sending it to the client. This
- // ensures that bots can see the full page content.
- if (isbot(request.headers.get("user-agent"))) {
- return handleBotRequest(
- request,
- responseStatusCode,
- responseHeaders,
- remixContext,
- locales,
- platform
- );
- }
-
- return handleBrowserRequest(
+ let remixServer = (
+ <OperatingSystemContextProvider platform={platform}>
+ <I18nProvider locale={locales?.[0] ?? "en-US"}>
+ <RemixServer context={remixContext} url={request.url} />
+ </I18nProvider>
+ </OperatingSystemContextProvider>
+ );
+ return handleRequest(
request,
responseStatusCode,
responseHeaders,
- remixContext,
- locales,
- platform
+ remixServer
);
}
-
-function handleBotRequest(
- request: Request,
- responseStatusCode: number,
- responseHeaders: Headers,
- remixContext: EntryContext,
- locales: string[],
- platform: OperatingSystemPlatform
-) {
- return new Promise((resolve, reject) => {
- let shellRendered = false;
- const { pipe, abort } = renderToPipeableStream(
- <OperatingSystemContextProvider platform={platform}>
- <I18nProvider locale={locales?.[0] ?? "en-US"}>
- <RemixServer
- context={remixContext}
- url={request.url}
- abortDelay={ABORT_DELAY}
- />
- </I18nProvider>
- </OperatingSystemContextProvider>,
- {
- onAllReady() {
- shellRendered = true;
- const body = new PassThrough();
- const stream = createReadableStreamFromReadable(body);
-
- responseHeaders.set("Content-Type", "text/html");
-
- resolve(
- new Response(stream, {
- headers: responseHeaders,
- status: responseStatusCode,
- })
- );
-
- pipe(body);
- },
- onShellError(error: unknown) {
- reject(error);
- },
- onError(error: unknown) {
- responseStatusCode = 500;
- // Log streaming rendering errors from inside the shell. Don't log
- // errors encountered during initial shell rendering since they'll
- // reject and get logged in handleDocumentRequest.
- if (shellRendered) {
- console.error(error);
- }
- },
- }
- );
-
- setTimeout(abort, ABORT_DELAY);
- });
-}
-
-function handleBrowserRequest(
- request: Request,
- responseStatusCode: number,
- responseHeaders: Headers,
- remixContext: EntryContext,
- locales: string[],
- platform: OperatingSystemPlatform
-) {
- return new Promise((resolve, reject) => {
- let shellRendered = false;
- const { pipe, abort } = renderToPipeableStream(
- <OperatingSystemContextProvider platform={platform}>
- <I18nProvider locale={locales?.[0] ?? "en-US"}>
- <RemixServer
- context={remixContext}
- url={request.url}
- abortDelay={ABORT_DELAY}
- />
- </I18nProvider>
- </OperatingSystemContextProvider>,
- {
- onShellReady() {
- shellRendered = true;
- const body = new PassThrough();
- const stream = createReadableStreamFromReadable(body);
-
- responseHeaders.set("Content-Type", "text/html");
-
- resolve(
- new Response(stream, {
- headers: responseHeaders,
- status: responseStatusCode,
- })
- );
-
- pipe(body);
- },
- onShellError(error: unknown) {
- reject(error);
- },
- onError(error: unknown) {
- responseStatusCode = 500;
- // Log streaming rendering errors from inside the shell. Don't log
- // errors encountered during initial shell rendering since they'll
- // reject and get logged in handleDocumentRequest.
- if (shellRendered) {
- console.error(error);
- }
- },
- }
- );
-
- setTimeout(abort, ABORT_DELAY);
- });
-}
-
-export function handleError(
- error: unknown,
- { request, params, context }: LoaderFunctionArgs
-) {
- logger.error(error, request);
-}
diff --git a/apps/developers/app/root.tsx b/apps/developers/app/root.tsx
index 38422c388a..f5109305c5 100644
--- a/apps/developers/app/root.tsx
+++ b/apps/developers/app/root.tsx
@@ -28,6 +28,8 @@ import { useMode } from "./hooks/useMode";
import { getSessionFlash } from "./services/session.server";
import { modeValidator } from "./types/validators";
+export const config = { runtime: "edge" };
+
export function links() {
return [
{ rel: "stylesheet", href: Tailwind },
diff --git a/apps/developers/app/routes/assets+/theme[.]css.ts b/apps/developers/app/routes/assets+/theme[.]css.ts
index e2f2f7cfdf..72d6d89e19 100644
--- a/apps/developers/app/routes/assets+/theme[.]css.ts
+++ b/apps/developers/app/routes/assets+/theme[.]css.ts
@@ -2,6 +2,8 @@ import { getThemeCode, themes } from "@carbon/utils";
import type { LoaderFunctionArgs } from "@vercel/remix";
import { getTheme } from "~/services/theme.server";
+export const config = { runtime: "nodejs" };
+
export async function loader({ request }: LoaderFunctionArgs) {
const theme = getTheme(request) as string;
diff --git a/apps/developers/app/utils/installGlobals.ts b/apps/developers/app/utils/installGlobals.ts
deleted file mode 100644
index 20581f6725..0000000000
--- a/apps/developers/app/utils/installGlobals.ts
+++ /dev/null
@@ -1,114 +0,0 @@
-import { installGlobals } from "@remix-run/node";
-import { IncomingMessage } from "node:http";
-
-export function installAndLockGlobals() {
- // @ts-ignore
- if (global.__installedAndLocked) {
- return;
- }
-
- installGlobals({ nativeFetch: true });
-
- const File = global.File;
- const Headers = global.Headers;
- const Request = global.Request;
- const Response = global.Response;
- const fetch = global.fetch;
- const FormData = global.FormData;
-
- /* @vercel/remix expects the non-native Headers API
- see: https://github.com/vercel/remix/blob/325c03d4c395b3c48aee88b1574c4688ee59251e/packages/vercel-remix/server.ts#L105
- This adds a minimal compatibility layer, though the result is different
- when multiple values for the same header are added.
- {
- "header": [
- "value1, value2"
- ]
- }
- vs
- {
- "header": [
- "value1",
- "value2"
- ]
- }
- This should be fine, but hasn't been extensively tested.
- Need to patch the prototype here since undici holds a reference.
- */
- if (!Object.hasOwn(Headers.prototype, "raw")) {
- Object.defineProperties(Headers.prototype, {
- raw: {
- value: function raw() {
- const entries: Iterable<[string, string]> = this.entries();
- return Object.fromEntries(
- Array.from(entries).map(([k, v]) => [k, [v]])
- );
- },
- configurable: true,
- },
- });
- }
-
- /* @vercel/remix doesn't set duplex when initializing a steaming body
- see: https://github.com/vercel/remix/blob/325c03d4c395b3c48aee88b1574c4688ee59251e/packages/vercel-remix/server.ts#L83-L94
- */
- class PatchedRequest extends Request {
- constructor(input: RequestInfo | URL, init: RequestInit = {}) {
- let initPatched = init;
- if (
- init.body &&
- init.body instanceof IncomingMessage &&
- init.duplex === undefined
- ) {
- initPatched = {
- ...init,
- duplex: "half",
- };
- }
- super(input, initPatched);
- }
- }
-
- // Ignore future changes to these properties
- Object.defineProperties(global, {
- File: {
- get() {
- return File;
- },
- set() {},
- },
- Headers: {
- get() {
- return Headers;
- },
- set() {},
- },
- Request: {
- get() {
- return PatchedRequest;
- },
- set() {},
- },
- Response: {
- get() {
- return Response;
- },
- set() {},
- },
- fetch: {
- get() {
- return fetch;
- },
- set() {},
- },
- FormData: {
- get() {
- return FormData;
- },
- set() {},
- },
- });
-
- // @ts-ignore
- global.__installedAndLocked = true;
-}
diff --git a/apps/developers/vite.config.ts b/apps/developers/vite.config.ts
index df3e081512..797b071e5a 100644
--- a/apps/developers/vite.config.ts
+++ b/apps/developers/vite.config.ts
@@ -24,6 +24,7 @@ export default defineConfig({
"react-dropzone",
"react-icons",
"react-phone-number-input",
+ "tailwind-merge",
],
},
server: {
@@ -33,7 +34,7 @@ export default defineConfig({
remix({
presets: [vercelPreset()],
future: {
- unstable_singleFetch: true,
+ unstable_singleFetch: false,
},
ignoredRouteFiles: ["**/.*"],
serverModuleFormat: "esm",