Skip to content

Commit 22c91dd

Browse files
Sandy-Garridomachour
authored andcommitted
fix(emotion): update example to use remix v2
1 parent fd37027 commit 22c91dd

File tree

4 files changed

+50
-49
lines changed

4 files changed

+50
-49
lines changed

emotion/app/root.tsx

+33-30
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { withEmotionCache } from "@emotion/react";
2-
import styled from "@emotion/styled";
32
import type { MetaFunction } from "@remix-run/node";
43
import {
54
Links,
@@ -8,23 +7,22 @@ import {
87
Outlet,
98
Scripts,
109
ScrollRestoration,
11-
useCatch,
10+
isRouteErrorResponse,
11+
useRouteError,
1212
} from "@remix-run/react";
1313
import { useContext, useEffect, useRef } from "react";
1414

1515
import ClientStyleContext from "~/styles/client.context";
1616
import ServerStyleContext from "~/styles/server.context";
1717

18-
const Container = styled("div")`
19-
background-color: #ff0000;
20-
padding: 1em;
21-
`;
2218

23-
export const meta: MetaFunction = () => ({
24-
charset: "utf-8",
25-
title: "Remix with Emotion",
26-
viewport: "width=device-width,initial-scale=1",
27-
});
19+
export const meta: MetaFunction = () => {
20+
return [
21+
{ name: "title", content: "Remix with Emotion" },
22+
{ name: "viewport", content: "width=device-width,initial-scale=1" },
23+
{ name: "charset", content: "utf-8" },
24+
]
25+
}
2826

2927
interface DocumentProps {
3028
children: React.ReactNode;
@@ -94,26 +92,31 @@ export default function App() {
9492
);
9593
}
9694

97-
export function CatchBoundary() {
98-
const caught = useCatch();
95+
export function ErrorBoundary() {
96+
const error = useRouteError();
9997

100-
return (
101-
<Document title={`${caught.status} ${caught.statusText}`}>
102-
<Container>
103-
<p>
104-
[CatchBoundary]: {caught.status} {caught.statusText}
105-
</p>
106-
</Container>
107-
</Document>
108-
);
109-
}
98+
if (isRouteErrorResponse(error)) {
99+
return (
100+
<div>
101+
<h1>Oops</h1>
102+
<p>Status: {error.status}</p>
103+
<p>{error.data.message}</p>
104+
</div>
105+
);
106+
}
107+
108+
// Don't forget to typecheck with your own logic.
109+
// Any value can be thrown, not just errors!
110+
let errorMessage = "Unknown error";
111+
if (error instanceof Error) {
112+
errorMessage = error.message;
113+
}
110114

111-
export function ErrorBoundary({ error }: { error: Error }) {
112115
return (
113-
<Document title="Error!">
114-
<Container>
115-
<p>[ErrorBoundary]: There was an error: {error.message}</p>
116-
</Container>
117-
</Document>
116+
<div>
117+
<h1>Uh oh ...</h1>
118+
<p>Something went wrong.</p>
119+
<pre>{errorMessage}</pre>
120+
</div>
118121
);
119-
}
122+
}

emotion/package.json

+14-14
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,25 @@
88
"typecheck": "tsc"
99
},
1010
"dependencies": {
11-
"@emotion/cache": "^11.7.1",
12-
"@emotion/react": "^11.8.1",
13-
"@emotion/server": "^11.4.0",
14-
"@emotion/styled": "^11.8.1",
15-
"@remix-run/node": "^1.19.3",
16-
"@remix-run/react": "^1.19.3",
17-
"@remix-run/serve": "^1.19.3",
11+
"@emotion/cache": "^11.11.0",
12+
"@emotion/react": "^11.11.1",
13+
"@emotion/server": "^11.11.0",
14+
"@emotion/styled": "^11.11.0",
15+
"@remix-run/node": "^2.0.0",
16+
"@remix-run/react": "^2.0.0",
17+
"@remix-run/serve": "^2.0.0",
1818
"react": "^18.2.0",
1919
"react-dom": "^18.2.0"
2020
},
2121
"devDependencies": {
22-
"@remix-run/dev": "^1.19.3",
23-
"@remix-run/eslint-config": "^1.19.3",
24-
"@types/react": "^18.2.14",
25-
"@types/react-dom": "^18.2.6",
26-
"eslint": "^8.27.0",
27-
"typescript": "^4.8.4"
22+
"@remix-run/dev": "^2.0.0",
23+
"@remix-run/eslint-config": "^2.0.0",
24+
"@types/react": "^18.2.22",
25+
"@types/react-dom": "^18.2.7",
26+
"eslint": "^8.49.0",
27+
"typescript": "^5.2.2"
2828
},
2929
"engines": {
30-
"node": ">=14.0.0"
30+
"node": ">=18.0.0"
3131
}
3232
}

emotion/remix.config.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
/** @type {import('@remix-run/dev').AppConfig} */
22
module.exports = {
3-
future: {
4-
v2_routeConvention: true,
5-
},
63
ignoredRouteFiles: ["**/.*"],
74
// appDirectory: "app",
85
// assetsBuildDirectory: "public/build",
96
// publicPath: "/build/",
107
// serverBuildPath: "build/index.js",
8+
serverModuleFormat: "cjs",
119
};

emotion/tsconfig.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"include": ["remix.env.d.ts", "**/*.ts", "**/*.tsx"],
33
"compilerOptions": {
4-
"lib": ["DOM", "DOM.Iterable", "ES2019"],
4+
"lib": ["DOM", "DOM.Iterable", "ES2022"],
55
"isolatedModules": true,
66
"esModuleInterop": true,
77
"jsx": "react-jsx",
88
"moduleResolution": "node",
99
"resolveJsonModule": true,
10-
"target": "ES2019",
10+
"target": "ES2022",
1111
"strict": true,
1212
"allowJs": true,
1313
"forceConsistentCasingInFileNames": true,

0 commit comments

Comments
 (0)