Skip to content

Commit

Permalink
Switch to React Router (#119)
Browse files Browse the repository at this point in the history
Signed-off-by: Nik Nasr <[email protected]>
  • Loading branch information
nikrooz authored Nov 23, 2024
1 parent d857f9f commit a5e88fc
Show file tree
Hide file tree
Showing 48 changed files with 706 additions and 3,297 deletions.
1 change: 1 addition & 0 deletions apps/web-ui/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
build
public/build
.env
.react-router
4 changes: 2 additions & 2 deletions apps/web-ui/app/entry.client.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RemixBrowser } from '@remix-run/react';
import { HydratedRouter } from 'react-router/dom';
import { startTransition, StrictMode } from 'react';
import { hydrateRoot } from 'react-dom/client';
import { register } from '@restate/data-access/middleware-service-worker';
Expand All @@ -8,7 +8,7 @@ register().then(() => {
hydrateRoot(
document,
<StrictMode>
<RemixBrowser />
<HydratedRouter />
</StrictMode>
);
});
Expand Down
19 changes: 0 additions & 19 deletions apps/web-ui/app/entry.server.tsx

This file was deleted.

15 changes: 13 additions & 2 deletions apps/web-ui/app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import {
Scripts,
ScrollRestoration,
useNavigate,
} from '@remix-run/react';
} from 'react-router';
import styles from './tailwind.css?url';
import type { LinksFunction } from '@remix-run/node';
import type { LinksFunction } from 'react-router';
import { LayoutOutlet, LayoutProvider, LayoutZone } from '@restate/ui/layout';
import { RouterProvider } from 'react-aria-components';
import { Button, Spinner } from '@restate/ui/button';
Expand All @@ -34,6 +34,11 @@ export const links: LinksFunction = () => [
rel: 'preconnect',
href: 'https://rsms.me/',
},
// TODO: move to the its own lib
{
rel: 'stylesheet',
href: 'https://unpkg.com/@stoplight/elements/styles.min.css',
},
{ rel: 'stylesheet', href: styles },
{ rel: 'stylesheet', href: 'https://rsms.me/inter/inter.css' },
{
Expand Down Expand Up @@ -85,6 +90,12 @@ export function Layout({ children }: { children: React.ReactNode }) {
</RouterProvider>
<ScrollRestoration />
<Scripts />
{/* TODO: move to its own lib */}
<script
src="https://unpkg.com/@stoplight/elements/web-components.min.js"
async
defer
></script>
</body>
</html>
);
Expand Down
7 changes: 7 additions & 0 deletions apps/web-ui/app/routes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { type RouteConfig, route, index } from '@react-router/dev/routes';

export default [
index('routes/_index.tsx'),
route('overview', 'routes/overview.tsx'),
route('invocations', 'routes/invocations.tsx'),
] satisfies RouteConfig;
2 changes: 1 addition & 1 deletion apps/web-ui/app/routes/_index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { redirect } from '@remix-run/react';
import { redirect } from 'react-router';

export const clientLoader = () => redirect('/overview');
export default () => null;
3 changes: 1 addition & 2 deletions apps/web-ui/app/tailwind.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@import '@stoplight/elements/styles.min.css';

/* @import 'https://unpkg.com/@stoplight/elements/styles.min.css'; */
@tailwind base;
@tailwind components;
@tailwind utilities;
Expand Down
1 change: 1 addition & 0 deletions apps/web-ui/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const BASE_URL = '/ui/';
8 changes: 3 additions & 5 deletions apps/web-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@
"scripts": {},
"type": "module",
"dependencies": {
"@remix-run/node": "^2.8.1",
"@remix-run/react": "^2.8.1",
"@remix-run/serve": "^2.8.1",
"@react-router/node": "7.0.0",
"isbot": "^4.4.0",
"react": "19.0.0-rc-65903583-20240805",
"react-dom": "19.0.0-rc-65903583-20240805"
"react-dom": "19.0.0-rc-65903583-20240805",
"react-router": "7.0.0"
},
"devDependencies": {
"@remix-run/dev": "^2.8.1",
"@types/react": "^18.2.0",
"@types/react-dom": "^18.2.0",
"eslint": "^8.56.0",
Expand Down
14 changes: 7 additions & 7 deletions apps/web-ui/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"options": {
"commands": [
{
"command": "cd apps/web-ui && ../../node_modules/.bin/remix vite:dev --port=4300"
"command": "cd apps/web-ui && ../../node_modules/.bin/react-router dev --port=4300"
}
]
},
Expand All @@ -22,7 +22,7 @@
"command": "nx serve mock-admin-api"
},
{
"command": "cd apps/web-ui && ADMIN_BASE_URL=http://localhost:4001 ../../node_modules/.bin/remix vite:dev --port=4300"
"command": "cd apps/web-ui && ADMIN_BASE_URL=http://localhost:4001 ../../node_modules/.bin/react-router dev --port=4300"
}
],
"parallel": true
Expand All @@ -33,7 +33,7 @@
"command": "nx serve mock-admin-api -c proxy"
},
{
"command": "cd apps/web-ui && ADMIN_BASE_URL=http://localhost:4001 ../../node_modules/.bin/remix vite:dev --port=4300"
"command": "cd apps/web-ui && ADMIN_BASE_URL=http://localhost:4001 ../../node_modules/.bin/react-router dev --port=4300"
}
],
"parallel": true
Expand All @@ -45,7 +45,7 @@
"options": {
"commands": [
"rm -R -f dist/apps/web-ui",
"cd apps/web-ui && ../../node_modules/.bin/remix vite:build",
"cd apps/web-ui && NODE_ENV=production ../../node_modules/.bin/react-router build",
"mkdir -p dist/apps/web-ui",
"mv apps/web-ui/build/client/* dist/apps/web-ui",
"rm -R apps/web-ui/build"
Expand All @@ -57,7 +57,7 @@
"executor": "nx:run-commands",
"options": {
"commands": [
"cd apps/web-ui && ../../node_modules/.bin/remix vite:build && ../../node_modules/.bin/vite preview --port=4300"
"cd apps/web-ui && NODE_ENV=production ../../node_modules/.bin/react-router build && ../../node_modules/.bin/vite preview --port=4300"
]
},
"configurations": {
Expand All @@ -67,7 +67,7 @@
"command": "nx serve mock-admin-api"
},
{
"command": "cd apps/web-ui && ../../node_modules/.bin/remix vite:build && ADMIN_BASE_URL=http://localhost:4001 ../../node_modules/.bin/vite preview --port=4300"
"command": "cd apps/web-ui && NODE_ENV=production && ADMIN_BASE_URL=http://localhost:4001 ../../node_modules/.bin/vite preview --port=4300"
}
],
"parallel": true
Expand All @@ -78,7 +78,7 @@
"command": "nx serve mock-admin-api -c proxy"
},
{
"command": "cd apps/web-ui && ../../node_modules/.bin/remix vite:build && ADMIN_BASE_URL=http://localhost:4001 ../../node_modules/.bin/vite preview --port=4300"
"command": "cd apps/web-ui && NODE_ENV=production ../../node_modules/.bin/react-router build && ADMIN_BASE_URL=http://localhost:4001 ../../node_modules/.bin/vite preview --port=4300"
}
],
"parallel": true
Expand Down
7 changes: 7 additions & 0 deletions apps/web-ui/react-router.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { Config } from '@react-router/dev/config';
import { BASE_URL } from './constants';

export default {
ssr: false,
basename: BASE_URL,
} satisfies Config;
2 changes: 0 additions & 2 deletions apps/web-ui/remix.env.d.ts

This file was deleted.

2 changes: 0 additions & 2 deletions apps/web-ui/test-setup.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
import { installGlobals } from '@remix-run/node';
import '@testing-library/jest-dom/matchers';
installGlobals();
4 changes: 2 additions & 2 deletions apps/web-ui/tests/routes/_index.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { createRemixStub } from '@remix-run/testing';
import { createRoutesStub } from 'react-router';
import { render, screen, waitFor } from '@testing-library/react';
import Index, { clientLoader } from '../../app/routes/_index';

test('renders loader data', async () => {
const RemixStub = createRemixStub([
const RemixStub = createRoutesStub([
{
path: '/',
Component: Index,
Expand Down
10 changes: 8 additions & 2 deletions apps/web-ui/tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"types": ["../../@types/vite.d.ts", "../../@types/global-env.d.ts"]
"types": [
"@react-router/node",
"vite/client",
"../../@types/vite.d.ts",
"../../@types/global-env.d.ts"
],
"rootDirs": [".", "./.react-router/types"]
},
"include": [
"remix.env.d.ts",
".react-router/types/**/*",
"app/**/*.ts",
"app/**/*.tsx",
"app/**/*.js",
Expand Down
8 changes: 5 additions & 3 deletions apps/web-ui/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"lib": ["DOM", "DOM.Iterable", "ES2019"],
"lib": ["DOM", "DOM.Iterable", "ES2022"],
"isolatedModules": true,
"esModuleInterop": true,
"jsx": "react-jsx",
"moduleResolution": "node",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"target": "ES2019",
"strict": true,
"allowJs": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true
"noEmit": true,
"skipLibCheck": true,
"module": "ESNext"
},
"include": [],
"files": [],
Expand Down
22 changes: 5 additions & 17 deletions apps/web-ui/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { vitePlugin as remix } from '@remix-run/dev';
import { defineConfig, loadEnv } from 'vite';
import { reactRouter } from '@react-router/dev/vite';
import { defineConfig, loadEnv, Plugin } from 'vite';
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
import license from 'rollup-plugin-license';
import path from 'path';
import { nodePolyfills } from 'vite-plugin-node-polyfills';

const BASE_URL = '/ui/';
import { BASE_URL } from './constants';

export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), '');
Expand Down Expand Up @@ -37,19 +35,9 @@ export default defineConfig(({ mode }) => {
return !env.isSsrBuild;
},
},
!process.env.VITEST &&
remix({
ssr: false,
basename: BASE_URL,
future: {
v3_fetcherPersist: true,
v3_relativeSplatPath: true,
v3_throwAbortReason: true,
},
}),
!process.env.VITEST && reactRouter(),
nxViteTsPaths(),
nodePolyfills(),
],
] as Plugin[],

// Uncomment this if you are using workers.
worker: {
Expand Down
2 changes: 1 addition & 1 deletion libs/features/overview-route/src/lib/DeleteDeployment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
DELETE_DEPLOYMENT_QUERY_PARAM,
DEPLOYMENT_QUERY_PARAM,
} from './constants';
import { Form, useSearchParams } from '@remix-run/react';
import { Form, useSearchParams } from 'react-router';
import { Button, SubmitButton } from '@restate/ui/button';
import { ErrorBanner } from '@restate/ui/error';
import { FormFieldInput } from '@restate/ui/form-field';
Expand Down
2 changes: 1 addition & 1 deletion libs/features/overview-route/src/lib/Deployment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import { Revision } from './Revision';
import { DEPLOYMENT_QUERY_PARAM } from './constants';
import { Link } from '@restate/ui/link';
import { useSearchParams } from '@remix-run/react';
import { useSearchParams } from 'react-router';
import { useRef } from 'react';

const styles = tv({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
DELETE_DEPLOYMENT_QUERY_PARAM,
DEPLOYMENT_QUERY_PARAM,
} from '../constants';
import { useSearchParams } from '@remix-run/react';
import { useSearchParams } from 'react-router';
import { Section, SectionContent, SectionTitle } from '@restate/ui/section';
import { Icon, IconName } from '@restate/ui/icons';
import {
Expand Down
2 changes: 1 addition & 1 deletion libs/features/overview-route/src/lib/Details/Service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
useModifyService,
useServiceDetails,
} from '@restate/data-access/admin-api';
import { Form, useSearchParams } from '@remix-run/react';
import { Form, useSearchParams } from 'react-router';
import { Handler } from '../Handler';
import { Icon, IconName } from '@restate/ui/icons';
import { ServiceType } from '../ServiceType';
Expand Down
6 changes: 2 additions & 4 deletions libs/features/overview-route/src/lib/Handler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '@restate/ui/popover';
import { ServicePlaygroundTrigger } from './ServicePlayground';
import { ComponentProps } from 'react';
import { JsonSchemaViewer } from './StopLight';
import { JsonSchemaViewer } from '@restate/ui/api';

const styles = tv({
base: 'flex flex-col gap-0.5 relative',
Expand Down Expand Up @@ -154,9 +154,7 @@ function HandlerInputOutput({
>
<JsonSchemaViewer
className="font-mono [&>*>[aria-haspopup]]:mt-2 [&>*[data-test='property-description']]:mt-2"
schema={schema as any}
disableCrumbs
renderRootTreeLines
schema={schema}
/>
</DropdownSection>
</PopoverContent>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Form } from '@remix-run/react';
import { Form } from 'react-router';
import {
createContext,
FormEvent,
Expand Down
2 changes: 1 addition & 1 deletion libs/features/overview-route/src/lib/Service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Deployment } from './Deployment';
import { TruncateWithTooltip } from '@restate/ui/tooltip';
import { Link } from '@restate/ui/link';
import { SERVICE_QUERY_PARAM } from './constants';
import { useSearchParams } from '@remix-run/react';
import { useSearchParams } from 'react-router';
import { useRef } from 'react';

const styles = tv({
Expand Down
12 changes: 3 additions & 9 deletions libs/features/overview-route/src/lib/ServicePlayground.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useSearchParams, useNavigate } from '@remix-run/react';
import { useSearchParams, useNavigate } from 'react-router';
import { useServiceOpenApi } from '@restate/data-access/admin-api';
import { Button } from '@restate/ui/button';
import { QueryDialog, DialogContent, DialogClose } from '@restate/ui/dialog';
Expand All @@ -7,7 +7,7 @@ import { SERVICE_PLAYGROUND_QUERY_PARAM } from './constants';
import { ComponentProps, useMemo } from 'react';
import { useRestateContext } from '@restate/features/restate-context';
import { tv } from 'tailwind-variants';
import { API } from './StopLight';
import { API } from '@restate/ui/api';

const styles = tv({
base: 'px-1.5 py-0.5 text-xs font-normal font-sans rounded-md flex items-center gap-1',
Expand Down Expand Up @@ -47,7 +47,6 @@ export function ServicePlaygroundTrigger({
}}
variant={variant}
className={styles({ className })}
onHover={() => import('@stoplight/elements')}
>
Playground
<Icon name={IconName.ExternalLink} className="w-3 h-3" />
Expand Down Expand Up @@ -79,12 +78,7 @@ export function ServicePlayground() {
>
{apiSpec ? (
<>
<API
apiDescriptionDocument={apiSpec}
router="hash"
hideExport
layout="responsive"
/>
<API apiDescriptionDocument={apiSpec} />
<DialogClose>
<Button variant="icon" className="absolute right-3 top-3">
<Icon name={IconName.X} className="w-5 h-5" />
Expand Down
Loading

0 comments on commit a5e88fc

Please sign in to comment.