Skip to content

Commit

Permalink
use custom livereload from 1.6.4 of remix
Browse files Browse the repository at this point in the history
  • Loading branch information
danieltott committed Aug 31, 2022
1 parent 79e5e0d commit 176d1cd
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion app/root.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { json } from '@remix-run/node';
import {
Outlet,
Links,
LiveReload,
Meta,
Scripts,
ScrollRestoration,
Expand Down Expand Up @@ -76,6 +75,49 @@ export function meta({ data: { meta } = {} } = {}) {
};
}

export const LiveReload =
process.env.NODE_ENV !== 'development'
? () => null
: function LiveReload({
port = Number(process.env.REMIX_DEV_SERVER_WS_PORT || 8002),
nonce = undefined,
}) {
let js = String.raw;
return (
<script
nonce={nonce}
suppressHydrationWarning
dangerouslySetInnerHTML={{
__html: js`
(() => {
let protocol = location.protocol === "https:" ? "wss:" : "ws:";
let host = location.hostname;
let socketPath = protocol + "//" + host + ":" + ${String(
port,
)} + "/socket";
let ws = new WebSocket(socketPath);
ws.onmessage = (message) => {
let event = JSON.parse(message.data);
if (event.type === "LOG") {
console.log(event.message);
}
if (event.type === "RELOAD") {
console.log("💿 Reloading window ...");
window.location.reload();
}
};
ws.onerror = (error) => {
console.log("Remix dev asset server web socket error:");
console.error(error);
};
})();
`,
}}
/>
);
};

export default function App() {
const location = useLocation();

Expand Down

0 comments on commit 176d1cd

Please sign in to comment.