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

bug: split route modules doesn't build with lingui #13266

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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 contributors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -369,3 +369,4 @@
- yuleicul
- zeromask1337
- zheng-chuang
- grz-gajda
6 changes: 6 additions & 0 deletions integration/helpers/vite-6-lingui-template/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules

/.cache
/build
.env
.react-router
23 changes: 23 additions & 0 deletions integration/helpers/vite-6-lingui-template/app/root.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Links, Meta, Outlet, Scripts, ScrollRestoration } from "react-router";
import { i18n } from "@lingui/core";
import { I18nProvider } from "@lingui/react";

export default function App() {
return (
<html lang="en">
<head>
<meta charSet="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<Meta />
<Links />
</head>
<body>
<I18nProvider i18n={i18n}>
<Outlet />
</I18nProvider>
<ScrollRestoration />
<Scripts />
</body>
</html>
);
}
4 changes: 4 additions & 0 deletions integration/helpers/vite-6-lingui-template/app/routes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { type RouteConfig } from "@react-router/dev/routes";
import { flatRoutes } from "@react-router/fs-routes";

export default flatRoutes() satisfies RouteConfig;
16 changes: 16 additions & 0 deletions integration/helpers/vite-6-lingui-template/app/routes/_index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { MetaFunction } from "react-router";

export const meta: MetaFunction = () => {
return [
{ title: "New React Router App" },
{ name: "description", content: "Welcome to React Router!" },
];
};

export default function Index() {
return (
<div style={{ fontFamily: "system-ui, sans-serif", lineHeight: "1.8" }}>
<h1>Welcome to React Router</h1>
</div>
);
}
2 changes: 2 additions & 0 deletions integration/helpers/vite-6-lingui-template/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/// <reference types="@react-router/node" />
/// <reference types="vite/client" />
46 changes: 46 additions & 0 deletions integration/helpers/vite-6-lingui-template/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"name": "integration-vite-6-template",
"version": "0.0.0",
"private": true,
"sideEffects": false,
"type": "module",
"scripts": {
"dev": "react-router dev",
"build": "react-router build",
"start": "react-router-serve ./build/server/index.js",
"typecheck": "react-router typegen && tsc"
},
"dependencies": {
"@lingui/core": "^5.2.0",
"@lingui/react": "^5.2.0",
"@react-router/express": "workspace:*",
"@react-router/node": "workspace:*",
"@react-router/serve": "workspace:*",
"@vanilla-extract/css": "^1.10.0",
"@vanilla-extract/vite-plugin": "^3.9.2",
"express": "^4.19.2",
"isbot": "^5.1.11",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router": "workspace:*",
"serialize-javascript": "^6.0.1"
},
"devDependencies": {
"@lingui/cli": "^5.2.0",
"@lingui/vite-plugin": "^5.2.0",
"@react-router/dev": "workspace:*",
"@react-router/fs-routes": "workspace:*",
"@react-router/remix-routes-option-adapter": "workspace:*",
"@types/react": "^18.2.20",
"@types/react-dom": "^18.2.7",
"eslint": "^8.38.0",
"typescript": "^5.1.6",
"vite": "^6.1.0",
"vite-plugin-babel-macros": "^1.0.6",
"vite-env-only": "^3.0.1",
"vite-tsconfig-paths": "^4.2.1"
},
"engines": {
"node": ">=20.0.0"
}
}
Binary file not shown.
22 changes: 22 additions & 0 deletions integration/helpers/vite-6-lingui-template/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"include": ["env.d.ts", "**/*.ts", "**/*.tsx", ".react-router/types/**/*"],
"compilerOptions": {
"lib": ["DOM", "DOM.Iterable", "ES2022"],
"verbatimModuleSyntax": true,
"esModuleInterop": true,
"jsx": "react-jsx",
"module": "ESNext",
"moduleResolution": "Bundler",
"resolveJsonModule": true,
"target": "ES2022",
"strict": true,
"allowJs": true,
"skipLibCheck": true,
"baseUrl": ".",
"paths": {
"~/*": ["./app/*"]
},
"noEmit": true,
"rootDirs": [".", ".react-router/types/"]
}
}
9 changes: 9 additions & 0 deletions integration/helpers/vite-6-lingui-template/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { reactRouter } from "@react-router/dev/vite";
import { defineConfig } from "vite";
import tsconfigPaths from "vite-tsconfig-paths";
import macrosPlugin from "vite-plugin-babel-macros";
import { lingui } from "@lingui/vite-plugin";

export default defineConfig({
plugins: [reactRouter(), macrosPlugin(), lingui(), tsconfigPaths()],
});
54 changes: 54 additions & 0 deletions integration/split-route-modules-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -543,4 +543,58 @@ test.describe("Split route modules", async () => {
});
});
});

test.describe("with support for @lingui", () => {
let splitRouteModules = true;
let port: number;
let cwd: string;

test.beforeAll(async () => {
port = await getPort();
cwd = await createProject({
"react-router.config.ts": reactRouterConfig({ splitRouteModules }),
"vite.config.js": await viteConfig.basic({ port }),
...files,
"app/routes/unsplittable.tsx": js`
import { t } from "@lingui/core/macro";
import type { Route } from "./+types/unsplittable";
import { Form } from "react-router";

// Dummy variable to prevent route exports from being split
let shared: null = null;

export const clientLoader = async () => {
return shared ?? t\`Hello from unsplittable client loader\`;
};

export const clientAction = async () => {
return shared ?? "Hello from unsplittable client action";
};

export function HydrateFallback() {
return shared ?? <div>Loading...</div>;
}

export default function UnsplittableRoute({
loaderData,
actionData,
}: Route.ComponentProps) {
return (
<>
<p>{loaderData}</p>
<p>{actionData}</p>
<Form method="post">
<button>Submit</button>
</Form>
</>
);
}`,
});
});

test("build passes", async () => {
let { status } = build({ cwd });
expect(status).toBe(0);
});
});
});
Loading