Skip to content

Commit

Permalink
[Chore] Upgrade to Remix 2.0 (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
inssein authored Nov 11, 2023
1 parent 2fac845 commit d28a490
Show file tree
Hide file tree
Showing 51 changed files with 6,690 additions and 8,830 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 20
cache: "npm"

- name: Get installed Playwright version
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 20
cache: "npm"

- name: Install dependencies
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
node_modules

/.cache
/functions/\[\[path\]\].js
/functions/\[\[path\]\].js.map
/.wrangler
/functions
/public/build
.env
.dev.vars
Expand Down
1 change: 1 addition & 0 deletions .idea/utiliti.dev.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .node-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16.13.0
20.9
6 changes: 3 additions & 3 deletions app/components/box.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default function Box({
<div
className={classNames(
"w-full border rounded-lg bg-zinc-700 border-zinc-600",
className
className,
)}
>
{children}
Expand Down Expand Up @@ -42,7 +42,7 @@ export function BoxContent({
className={classNames(
"bg-zinc-800 max-h-96 overflow-auto not-prose",
isLast && "rounded-b-lg",
className
className,
)}
>
{children}
Expand All @@ -66,7 +66,7 @@ export function BoxOptions({
<div
className={classNames(
"px-3 py-2 flex border-t border-gray-600 bg-zinc-800/50 items-center",
isLast && "rounded-b-lg"
isLast && "rounded-b-lg",
)}
>
{children}
Expand Down
2 changes: 1 addition & 1 deletion app/components/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function Button(props: Props) {
{...buttonProps}
className={classNames(
"inline-flex items-center py-2.5 px-4 text-xs font-medium text-center text-white bg-orange-600 rounded-lg hover:bg-orange-800",
className
className,
)}
>
{props.label}
Expand Down
22 changes: 9 additions & 13 deletions app/components/code.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Editor from "react-simple-code-editor";
// @ts-ignore
import { highlight, languages } from "prismjs/components/prism-core";
import "prismjs/components/prism-clike";
import "prismjs/components/prism-javascript";
import "prismjs/components/prism-sql";
import "prismjs/components/prism-markup";
import hljs from "highlight.js/lib/core";
import javascript from "highlight.js/lib/languages/javascript";
import sql from "highlight.js/lib/languages/sql";

hljs.registerLanguage("javascript", javascript);
hljs.registerLanguage("sql", sql);

interface Props {
readonly readonly: boolean;
Expand All @@ -23,16 +23,12 @@ export default function Code({
language = "javascript",
placeholder = "Paste some json…",
}: Props) {
const CodeEditor = (Editor as any).default;
return (
<Editor
<CodeEditor
value={value}
onValueChange={setValue}
highlight={(code) =>
highlight(
code,
language === "javascript" ? languages.js : languages.sql
)
}
highlight={(code: string) => hljs.highlight(code, { language }).value}
placeholder={placeholder}
style={{
fontFamily: '"Fira code", monospace',
Expand Down
2 changes: 1 addition & 1 deletion app/components/google-ad.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function GoogleAd() {
const scriptTag = document.createElement("script");
scriptTag.setAttribute(
"src",
"https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-9826263890932106"
"https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-9826263890932106",
);
scriptTag.setAttribute("type", "text/javascript");
scriptTag.setAttribute("async", "async");
Expand Down
4 changes: 2 additions & 2 deletions app/components/json-viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ export default function JsonViewer({ json }: Props) {

return level < expandAfter;
},
[shouldExpand, expandAfter]
[shouldExpand, expandAfter],
);

const expandAll = useCallback(() => setShouldExpand(true), [setShouldExpand]);
const collapseALl = useCallback(
() => setShouldExpand(false),
[setShouldExpand]
[setShouldExpand],
);

const incrementExpandAfter = useCallback(() => {
Expand Down
2 changes: 1 addition & 1 deletion app/components/number-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default forwardRef<
type="number"
className={classNames(
"block text-sm border rounded-lg bg-zinc-700 border-zinc-600 placeholder-zinc-400 text-white focus:ring-orange-500 focus:border-orange-500",
className
className,
)}
{...rest}
/>
Expand Down
4 changes: 2 additions & 2 deletions app/components/read-file.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface Props {
export default function ReadFile({ accept, onLoad, type = "text" }: Props) {
const onButtonClick = useCallback(
() => document.getElementById("file-input")?.click(),
[]
[],
);
const onChange = useCallback(
(e: ChangeEvent<HTMLInputElement>) => {
Expand Down Expand Up @@ -46,7 +46,7 @@ export default function ReadFile({ accept, onLoad, type = "text" }: Props) {
break;
}
},
[onLoad, type]
[onLoad, type],
);

return (
Expand Down
6 changes: 3 additions & 3 deletions app/components/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default function Search({ open, setOpen }: Props) {
setOpen(false);
navigate(item.url);
},
[navigate, setOpen]
[navigate, setOpen],
);

return (
Expand Down Expand Up @@ -90,7 +90,7 @@ export default function Search({ open, setOpen }: Props) {
className={({ active }) =>
classNames(
"flex cursor-default select-none items-center rounded-md px-3 py-2",
active && "bg-zinc-800 text-orange-600"
active && "bg-zinc-800 text-orange-600",
)
}
>
Expand All @@ -107,7 +107,7 @@ export default function Search({ open, setOpen }: Props) {
</>
)}
</Combobox.Option>
)
),
)}
</ul>
</li>
Expand Down
4 changes: 2 additions & 2 deletions app/components/tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export function useTooltip({
...interactions,
...data,
}),
[open, setOpen, interactions, data]
[open, setOpen, interactions, data],
);
}

Expand Down Expand Up @@ -120,7 +120,7 @@ export const TooltipTrigger = React.forwardRef<
...props,
...children.props,
"data-state": context.open ? "open" : "closed",
})
}),
);
}

Expand Down
6 changes: 3 additions & 3 deletions app/components/utiliti.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ interface Props<T> {
readonly actions: Record<string, (input: string) => Promise<T>>;
readonly renderInput: (
input: string,
setInput: (input: string) => void
setInput: (input: string) => void,
) => ReactNode;
readonly renderOutput: (
action: string,
input: string,
output: T
output: T,
) => ReactNode;
readonly renderOptions?: () => ReactNode;
readonly showLoadFile?: Boolean;
Expand Down Expand Up @@ -57,7 +57,7 @@ export default function Utiliti<T>({
setOutput(null);
});
},
[actions]
[actions],
);

return (
Expand Down
26 changes: 8 additions & 18 deletions app/entry.client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,14 @@ import { RemixBrowser } from "@remix-run/react";
import { startTransition, StrictMode } from "react";
import { hydrateRoot } from "react-dom/client";

function hydrate() {
startTransition(() => {
hydrateRoot(
document,
<StrictMode>
<RemixBrowser />
</StrictMode>
);
});
}

if (typeof requestIdleCallback === "function") {
requestIdleCallback(hydrate);
} else {
// Safari doesn't support requestIdleCallback
// https://caniuse.com/requestidlecallback
setTimeout(hydrate, 1);
}
startTransition(() => {
hydrateRoot(
document,
<StrictMode>
<RemixBrowser />
</StrictMode>,
);
});

// add a service worker, only in production for now
if (
Expand Down
31 changes: 22 additions & 9 deletions app/entry.server.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
import type { EntryContext } from "@remix-run/cloudflare";
import type { AppLoadContext, EntryContext } from "@remix-run/cloudflare";
import { RemixServer } from "@remix-run/react";
import { renderToString } from "react-dom/server";
import isbot from "isbot";
import { renderToReadableStream } from "react-dom/server";

export default function handleRequest(
export default async function handleRequest(
request: Request,
responseStatusCode: number,
responseHeaders: Headers,
remixContext: EntryContext
remixContext: EntryContext,
loadContext: AppLoadContext,
) {
const markup = renderToString(
<RemixServer context={remixContext} url={request.url} />
const body = await renderToReadableStream(
<RemixServer context={remixContext} url={request.url} />,
{
signal: request.signal,
onError(error: unknown) {
// Log streaming rendering errors from inside the shell
console.error(error);
responseStatusCode = 500;
},
},
);

responseHeaders.set("Content-Type", "text/html");
if (isbot(request.headers.get("user-agent"))) {
await body.allReady;
}

return new Response("<!DOCTYPE html>" + markup, {
status: responseStatusCode,
responseHeaders.set("Content-Type", "text/html");
return new Response(body, {
headers: responseHeaders,
status: responseStatusCode,
});
}
4 changes: 2 additions & 2 deletions app/hooks/use-local-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useState } from "react";
export function useLocalStorage<T>(
key: string,
initialValue: T,
json: boolean = false
json: boolean = false,
): [T, (v: T) => void] {
const [storedValue, setStoredValue] = useState(() => {
if (typeof window === "undefined") {
Expand Down Expand Up @@ -32,7 +32,7 @@ export function useLocalStorage<T>(
if (typeof window !== "undefined") {
window.localStorage.setItem(
key,
json ? JSON.stringify(value) : (value as string)
json ? JSON.stringify(value) : (value as string),
);
}
} catch (error) {
Expand Down
12 changes: 7 additions & 5 deletions app/root.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { LinksFunction, V2_MetaFunction } from "@remix-run/cloudflare";
import type { LinksFunction, MetaFunction } from "@remix-run/cloudflare";
import { cssBundleHref } from "@remix-run/css-bundle";
import {
isRouteErrorResponse,
Link,
Expand All @@ -10,12 +11,12 @@ import {
ScrollRestoration,
useRouteError,
} from "@remix-run/react";
import prism from "app/styles/prism-darcula.css";
import tailwind from "~/styles/tailwind.css";
import tailwind from "./styles/tailwind.css";
import highlight from "highlight.js/styles/stackoverflow-dark.css";
import Layout from "~/components/layout";
import { ArrowSmallLeftIcon } from "@heroicons/react/24/solid";

export const meta: V2_MetaFunction = () => {
export const meta: MetaFunction = () => {
const title = "Utiliti";
const description =
"A collection of high quality, secure, and open source utilities.";
Expand Down Expand Up @@ -74,13 +75,14 @@ export const links: LinksFunction = () => [
{ rel: "shortcut icon", href: "/assets/favicon.ico" },
{ rel: "manifest", href: "/assets/site.webmanifest" },
{ rel: "stylesheet", href: tailwind },
{ rel: "stylesheet", href: prism },
{ rel: "stylesheet", href: highlight },
{ rel: "preconnect", href: "https://fonts.googleapis.com" },
{ rel: "preconnect", href: "https://fonts.gstatic.com" },
{
rel: "stylesheet",
href: "https://fonts.googleapis.com/css2?family=Fira+Code&display=swap",
},
...(cssBundleHref ? [{ rel: "stylesheet", href: cssBundleHref }] : []),
];

export default function App() {
Expand Down
Loading

0 comments on commit d28a490

Please sign in to comment.