Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move server-runtime into react-router #11698

Merged
merged 14 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changeset/collapse-packages.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@

- Collapse `@remix-run/router` into `react-router`
- Collapse `react-router-dom` into `react-router`
- Collapse `@remix-run/server-runtime` into `react-router`
- Collapse `@remix-run/testing` into `react-router`
3 changes: 1 addition & 2 deletions .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
"@react-router/dev",
"@react-router/express",
"@react-router/node",
"@react-router/serve",
"@react-router/server-runtime"
"@react-router/serve"
]
],
"linked": [],
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ This repository is a monorepo containing the following packages:
- [`@react-router/express`](/packages/remix-express)
- [`@react-router/node`](/packages/remix-node)
- [`@react-router/serve`](/packages/remix-serve)
- [`@react-router/server-runtime`](/packages/remix-server-runtime)
- [`react-router`](/packages/react-router)
- [`react-router-dom`](/packages/react-router-dom)

Expand Down
2 changes: 1 addition & 1 deletion integration/client-data-test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test, expect } from "@playwright/test";

import { UNSAFE_ServerMode as ServerMode } from "@react-router/server-runtime";
import { UNSAFE_ServerMode as ServerMode } from "react-router";
import {
createAppFixture,
createFixture,
Expand Down
2 changes: 1 addition & 1 deletion integration/error-boundary-test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test, expect } from "@playwright/test";

import { UNSAFE_ServerMode as ServerMode } from "@react-router/server-runtime";
import { UNSAFE_ServerMode as ServerMode } from "react-router";
import {
createAppFixture,
createFixture,
Expand Down
2 changes: 1 addition & 1 deletion integration/error-boundary-v2-test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Page } from "@playwright/test";
import { test, expect } from "@playwright/test";

import { UNSAFE_ServerMode as ServerMode } from "@react-router/server-runtime";
import { UNSAFE_ServerMode as ServerMode } from "react-router";
import {
createAppFixture,
createFixture,
Expand Down
4 changes: 2 additions & 2 deletions integration/error-data-request-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ test.describe("ErrorBoundary", () => {
`,

[`app/routes/loader-return-json.jsx`]: js`
import { json } from "@react-router/server-runtime";
import { json } from "react-router";

export async function loader() {
return json({ ok: true });
Expand All @@ -80,7 +80,7 @@ test.describe("ErrorBoundary", () => {
`,

[`app/routes/action-return-json.jsx`]: js`
import { json } from "@react-router/server-runtime";
import { json } from "react-router";

export async function action() {
return json({ ok: true });
Expand Down
8 changes: 5 additions & 3 deletions integration/error-sanitization-test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { test, expect } from "@playwright/test";
import { UNSAFE_ErrorResponseImpl as ErrorResponseImpl } from "react-router";
import {
UNSAFE_ErrorResponseImpl as ErrorResponseImpl,
UNSAFE_ServerMode as ServerMode,
} from "react-router";

import { UNSAFE_ServerMode as ServerMode } from "@react-router/server-runtime";
import type { Fixture } from "./helpers/create-fixture.js";
import {
createAppFixture,
Expand Down Expand Up @@ -77,7 +79,7 @@ const routeFiles = {

"app/routes/defer.tsx": js`
import * as React from 'react';
import { defer } from "@react-router/server-runtime";
import { defer } from "react-router";
import { Await, useAsyncError, useLoaderData, useRouteError } from "react-router-dom";

export function loader({ request }) {
Expand Down
4 changes: 2 additions & 2 deletions integration/form-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ test.describe("Forms", () => {
`,

"app/routes/empty-file-upload.tsx": js`
import { json } from "@react-router/server-runtime";
import { json } from "react-router";
import { Form, useActionData } from "react-router-dom";

export async function action({ request }) {
Expand Down Expand Up @@ -454,7 +454,7 @@ test.describe("Forms", () => {
"myfile.txt": "stuff",

"app/routes/pathless-layout-parent.tsx": js`
import { json } from '@react-router/server-runtime'
import { json } from "react-router"
import { Form, Outlet, useActionData } from 'react-router-dom'

export async function action({ request }) {
Expand Down
4 changes: 2 additions & 2 deletions integration/headers-test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test, expect } from "@playwright/test";

import { UNSAFE_ServerMode as ServerMode } from "@react-router/server-runtime";
import { UNSAFE_ServerMode as ServerMode } from "react-router";
import { createFixture, js } from "./helpers/create-fixture.js";
import type { Fixture } from "./helpers/create-fixture.js";

Expand Down Expand Up @@ -159,7 +159,7 @@ test.describe.skip("headers export", () => {
`,

"app/routes/cookie.tsx": js`
import { json } from "@react-router/server-runtime";
import { json } from "react-router";
import { Outlet } from "react-router-dom";

export function loader({ request }) {
Expand Down
10 changes: 6 additions & 4 deletions integration/helpers/create-fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import stripIndent from "strip-indent";
import { sync as spawnSync, spawn } from "cross-spawn";
import type { JsonObject } from "type-fest";

import { UNSAFE_ServerMode as ServerMode } from "@react-router/server-runtime";
import type { ServerBuild } from "@react-router/server-runtime";
import { createRequestHandler } from "@react-router/server-runtime";
import {
type ServerBuild,
createRequestHandler,
UNSAFE_ServerMode as ServerMode,
UNSAFE_decodeViaTurboStream as decodeViaTurboStream,
} from "react-router";
import { createRequestHandler as createExpressHandler } from "@react-router/express";
import { installGlobals } from "@react-router/node";
import { UNSAFE_decodeViaTurboStream as decodeViaTurboStream } from "react-router";

import { viteConfig } from "./vite.js";

Expand Down
1 change: 0 additions & 1 deletion integration/helpers/node-template/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"@react-router/express": "workspace:*",
"@react-router/node": "workspace:*",
"@react-router/serve": "workspace:*",
"@react-router/server-runtime": "workspace:*",
"express": "^4.17.1",
"isbot": "^4.1.0",
"react": "^18.2.0",
Expand Down
1 change: 0 additions & 1 deletion integration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"@react-router/dev": "workspace:*",
"@react-router/express": "workspace:*",
"@react-router/node": "workspace:*",
"@react-router/server-runtime": "workspace:*",
"@types/express": "^4.17.9",
"@vanilla-extract/css": "^1.10.0",
"@vanilla-extract/vite-plugin": "^3.9.2",
Expand Down
2 changes: 1 addition & 1 deletion integration/resource-routes-test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test, expect } from "@playwright/test";

import { UNSAFE_ServerMode as ServerMode } from "@react-router/server-runtime";
import { UNSAFE_ServerMode as ServerMode } from "react-router";
import {
createAppFixture,
createFixture,
Expand Down
2 changes: 1 addition & 1 deletion integration/root-route-test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test, expect } from "@playwright/test";

import { UNSAFE_ServerMode as ServerMode } from "@react-router/server-runtime";
import { UNSAFE_ServerMode as ServerMode } from "react-router";
import {
createAppFixture,
createFixture,
Expand Down
2 changes: 1 addition & 1 deletion integration/single-fetch-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
js,
} from "./helpers/create-fixture.js";
import { PlaywrightFixture } from "./helpers/playwright-fixture.js";
import { UNSAFE_ServerMode as ServerMode } from "@react-router/server-runtime";
import { UNSAFE_ServerMode as ServerMode } from "react-router";

const ISO_DATE = "2024-03-12T12:00:00.000Z";

Expand Down
2 changes: 0 additions & 2 deletions jest/jest.config.shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ module.exports = {
"@react-router/express$": "<rootDir>/../remix-express/index.ts",
"@react-router/node$": "<rootDir>/../remix-node/index.ts",
"@react-router/serve$": "<rootDir>/../remix-serve/index.ts",
"@react-router/server-runtime$":
"<rootDir>/../remix-server-runtime/index.ts",
"^react-router$": "<rootDir>/../react-router/index.ts",
"^@web3-storage/multipart-parser$": require.resolve(
"@web3-storage/multipart-parser"
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@
},
"filesize": {
"packages/react-router/dist/react-router.production.min.js": {
"none": "120 kB"
"none": "124 kB"
},
"packages/react-router/dist/umd/react-router.production.min.js": {
"none": "125 kB"
"none": "130 kB"
}
},
"pnpm": {
Expand Down
10 changes: 0 additions & 10 deletions packages/react-router/.eslintrc

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
let restrictedGlobalsError = `Node globals are not allowed in this package.`;

module.exports = {
extends: "../../.eslintrc",
env: {
browser: true,
commonjs: true,
},
rules: {
strict: 0,
"no-restricted-syntax": ["error", "LogicalExpression[operator='??']"],
Comment on lines +4 to +10
Copy link
Member Author

@markdalgleish markdalgleish Jun 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just porting across equivalent config from .eslintrc (removed above) since it was converted to .eslintrc.js so it can include the options from the server-runtime package.

"no-restricted-globals": [
"error",
{ name: "__dirname", message: restrictedGlobalsError },
Expand Down
4 changes: 3 additions & 1 deletion packages/react-router/__tests__/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"jest": true
},
"rules": {
"no-console": 0
"no-console": 0,
"no-restricted-globals": "off",
"import/no-nodejs-modules": "off"
}
}
5 changes: 4 additions & 1 deletion packages/react-router/__tests__/router/data-strategy-test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import type { DataStrategyFunction, DataStrategyMatch } from "../../lib/router";
import type {
unstable_DataStrategyFunction as DataStrategyFunction,
unstable_DataStrategyMatch as DataStrategyMatch,
} from "../../lib/router";
import { json } from "../../lib/router";
import { createDeferred, setup } from "./utils/data-router-setup";
import { createFormData, tick } from "./utils/utils";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { createCookieFactory, isCookie } from "../cookies";
import type { SignFunction, UnsignFunction } from "../crypto";
import {
createCookieFactory,
isCookie,
} from "../../lib/server-runtime/cookies";
import type {
SignFunction,
UnsignFunction,
} from "../../lib/server-runtime/crypto";

const sign: SignFunction = async (value, secret) => {
return JSON.stringify({ value, secret });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { UNSAFE_decodeViaTurboStream as decodeViaTurboStream } from "react-router";

import type { ServerBuild } from "../build";
import { createRequestHandler } from "../server";
import type { ServerBuild } from "../../lib/server-runtime/build";
import { createRequestHandler } from "../../lib/server-runtime/server";

describe("loaders", () => {
// so that HTML/Fetch requests are the same, and so redirects don't hang on to
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { parseMultipartFormData } from "../formData";
/**
* @jest-environment node
*/
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was needed in a few tests since react-router uses jsdom as its default environment, resulting in a few test failures when moving tests across.


import { parseMultipartFormData } from "../../lib/server-runtime/formData";

declare global {
interface RequestInit {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { UNSAFE_ErrorResponseImpl as ErrorResponseImpl } from "react-router";

import type { ServerBuild } from "../build";
import { createRequestHandler } from "../server";
import { json } from "../responses";
import type { ServerBuild } from "../../lib/server-runtime/build";
import { createRequestHandler } from "../../lib/server-runtime/server";
import { json } from "../../lib/server-runtime/responses";

function getHandler(routeModule = {}, entryServerModule = {}) {
let routeId = "root";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { json } from "../responses";
import { createRequestHandler } from "../server";
import { json } from "../../lib/server-runtime/responses";
import { createRequestHandler } from "../../lib/server-runtime/server";

describe("createRequestHandler", () => {
it("retains request headers when stripping body off for loaders", async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import vm from "vm";

import { escapeHtml } from "../markup";
import { escapeHtml } from "../../lib/server-runtime/markup";

describe("escapeHtml", () => {
// These tests are based on https://github.com/zertosh/htmlescape/blob/3e6cf0614dd0f778fd0131e69070b77282150c15/test/htmlescape-test.js
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import type { TypedResponse } from "../index";
import { json, redirect } from "../index";
/**
* @jest-environment node
*/

import type { TypedResponse } from "../../lib/server-runtime/responses";
import { json, redirect } from "../../lib/server-runtime/responses";
import { isEqual } from "./utils";

describe("json", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
/**
* @jest-environment node
*/

import type { StaticHandlerContext } from "react-router";
import { json } from "react-router";

import { createRequestHandler } from "..";
import { ServerMode } from "../mode";
import type { ServerBuild } from "../build";
import { createRequestHandler } from "../../lib/server-runtime/server";
import { ServerMode } from "../../lib/server-runtime/mode";
import type { ServerBuild } from "../../lib/server-runtime/build";
import { mockServerBuild } from "./utils";

function spyConsole() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { createCookieFactory } from "../cookies";
import type { SignFunction, UnsignFunction } from "../crypto";
import { createCookieFactory } from "../../lib/server-runtime/cookies";
import type {
SignFunction,
UnsignFunction,
} from "../../lib/server-runtime/crypto";
import {
createSession,
createSessionStorageFactory,
isSession,
} from "../sessions";
import { createCookieSessionStorageFactory } from "../sessions/cookieStorage";
import { createMemorySessionStorageFactory } from "../sessions/memoryStorage";
} from "../../lib/server-runtime/sessions";
import { createCookieSessionStorageFactory } from "../../lib/server-runtime/sessions/cookieStorage";
import { createMemorySessionStorageFactory } from "../../lib/server-runtime/sessions/memoryStorage";

function getCookieFromSetCookie(setCookie: string): string {
return setCookie.split(/;\s*/)[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ import type {
HandleErrorFunction,
HeadersFunction,
LoaderFunction,
} from "../";
import type { FutureConfig } from "../entry";
import type { EntryRoute, ServerRoute, ServerRouteManifest } from "../routes";
} from "../../lib/server-runtime";
import type { FutureConfig } from "../../lib/server-runtime/entry";
import type {
EntryRoute,
ServerRoute,
ServerRouteManifest,
} from "../../lib/server-runtime/routes";

export function mockServerBuild(
routes: Record<
Expand Down
5 changes: 5 additions & 0 deletions packages/react-router/__tests__/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,8 @@ if (!globalThis.TransformStream) {
const { TransformStream } = require("node:stream/web");
globalThis.TransformStream = TransformStream;
}

if (!globalThis.File) {
const { File } = require("undici");
globalThis.File = File;
}
Loading
Loading