Skip to content

Commit 808a8d2

Browse files
authored
refactor(_official-realtime-app): use SSE utils from remix-utils instead of re-inventing the wheel (#87)
* Install Remix Utils * Replace hooks and functions with Remix Utils versions * Upgrade Remix Utils * Fix lint errors
1 parent b783f6e commit 808a8d2

File tree

6 files changed

+11
-74
lines changed

6 files changed

+11
-74
lines changed

_official-realtime-app/app/event-stream.ts

Lines changed: 0 additions & 35 deletions
This file was deleted.

_official-realtime-app/app/root.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ import {
44
Meta,
55
Outlet,
66
Scripts,
7-
ScrollRestoration,
7+
ScrollRestoration
88
} from "@remix-run/react";
99
import { useEffect } from "react";
10+
import { useEventSource } from "remix-utils";
1011

11-
import { useEventSource } from "~/use-event-source";
1212
import { useRevalidator } from "~/use-revalidator";
1313

14-
import styles from "./styles.processed.css";
1514
import icons from "./icons.svg";
15+
import styles from "./styles.processed.css";
1616

1717
export const meta: MetaFunction = () => ({
1818
charset: "utf-8",

_official-realtime-app/app/routes/issues-events.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { type DataFunctionArgs } from "@remix-run/node";
2+
import { eventStream } from "remix-utils";
23

3-
import { eventStream } from "../event-stream";
44
import { emitter, EVENTS } from "../events";
55

66
export const loader = ({ request }: DataFunctionArgs) => {
7-
return eventStream(request, (send) => {
7+
return eventStream(request.signal, (send) => {
88
const handler = (message: string) => {
9-
send("message", message);
9+
send({ data: message });
1010
};
1111

1212
emitter.addListener(EVENTS.ISSUE_CHANGED, handler);

_official-realtime-app/app/use-event-source.tsx

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
1-
import { useFetcher } from "@remix-run/react";
2-
import { useCallback, useMemo } from "react";
1+
import { useMemo } from "react";
2+
import { useDataRefresh } from "remix-utils";
33

44
// FIXME: This is unneeded after https://github.com/remix-run/remix/issues/4485
55
export function useRevalidator() {
6-
const fetcher = useFetcher();
6+
const { refresh } = useDataRefresh();
77

8-
const revalidate = useCallback(
9-
() => {
10-
fetcher.submit(null, { action: "/", method: "post" });
11-
},
12-
// eslint-disable-next-line react-hooks/exhaustive-deps
13-
[]
14-
);
15-
16-
return useMemo(() => ({ revalidate }), [revalidate]);
8+
return useMemo(() => ({ revalidate: refresh }), [refresh]);
179
}

_official-realtime-app/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"isbot": "^3.6.5",
2323
"react": "^18.2.0",
2424
"react-dom": "^18.2.0",
25+
"remix-utils": "^4.2.1",
2526
"tiny-invariant": "^1.3.1"
2627
},
2728
"devDependencies": {

0 commit comments

Comments
 (0)