Skip to content

Commit 2e162a0

Browse files
Remove LiveReload, enable action-test (remix-run#11416)
1 parent 9ff1297 commit 2e162a0

File tree

13 files changed

+4
-242
lines changed

13 files changed

+4
-242
lines changed

integration/helpers/cf-template/app/root.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import type { LinksFunction } from "@remix-run/cloudflare";
22
import { cssBundleHref } from "@remix-run/css-bundle";
33
import {
44
Links,
5-
LiveReload,
65
Meta,
76
Outlet,
87
Scripts,
@@ -26,7 +25,6 @@ export default function App() {
2625
<Outlet />
2726
<ScrollRestoration />
2827
<Scripts />
29-
<LiveReload />
3028
</body>
3129
</html>
3230
);

integration/helpers/deno-template/app/root.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { cssBundleHref } from "@remix-run/css-bundle";
22
import type { LinksFunction } from "@remix-run/deno";
33
import {
44
Links,
5-
LiveReload,
65
Meta,
76
Outlet,
87
Scripts,
@@ -27,7 +26,6 @@ export default function App() {
2726
<Outlet />
2827
<ScrollRestoration />
2928
<Scripts />
30-
<LiveReload />
3129
</body>
3230
</html>
3331
);

integration/helpers/node-template/app/root.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {
22
Links,
3-
LiveReload,
43
Meta,
54
Outlet,
65
Scripts,
@@ -20,7 +19,6 @@ export default function App() {
2019
<Outlet />
2120
<ScrollRestoration />
2221
<Scripts />
23-
<LiveReload />
2422
</body>
2523
</html>
2624
);

integration/playwright.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const config: PlaywrightTestConfig = {
66
testMatch: ["**/*-test.ts"],
77
// TODO: Temporary! Remove from this list as we get each suite passing
88
testIgnore: [
9-
"**/action-test.ts",
109
"**/client-data-test.ts",
1110
"**/error-sanitization-test.ts",
1211
"**/file-uploads-test.ts",

integration/vite-dev-custom-entry-test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ test.describe("Vite custom entry dev", () => {
9494
}
9595
`,
9696
"app/root.tsx": js`
97-
import { Links, Meta, Outlet, Scripts, LiveReload } from "react-router-dom";
97+
import { Links, Meta, Outlet, Scripts } from "react-router-dom";
9898
9999
export default function Root() {
100100
return (
@@ -109,7 +109,6 @@ test.describe("Vite custom entry dev", () => {
109109
<Outlet />
110110
</div>
111111
<Scripts />
112-
<LiveReload />
113112
</body>
114113
</html>
115114
);

integration/vite-manifests-test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const TEST_ROUTES = [
2424

2525
const files = {
2626
"app/root.tsx": `
27-
import { Links, Meta, Outlet, Scripts, LiveReload } from "react-router-dom";
27+
import { Links, Meta, Outlet, Scripts } from "react-router-dom";
2828
2929
export default function Root() {
3030
return (
@@ -36,7 +36,6 @@ const files = {
3636
<body>
3737
<Outlet />
3838
<Scripts />
39-
<LiveReload />
4039
</body>
4140
</html>
4241
);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"pretest:integration": "pnpm build",
1717
"test:integration": "pnpm playwright:integration",
1818
"posttest:integration": "pnpm clean:integration",
19-
"playwright:integration": "playwright test --config ./integration/playwright.config.ts --project chromium",
19+
"playwright:integration": "playwright test --config ./integration/playwright.config.ts --project=chromium",
2020
"changeset": "changeset",
2121
"version": "changeset version && node ./scripts/remove-prerelease-changelogs.mjs",
2222
"publish": "node scripts/publish.js",

packages/react-router-dom/__tests__/ssr/components-test.tsx

Lines changed: 0 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -9,92 +9,11 @@ import {
99
Outlet,
1010
RouterProvider,
1111
} from "../../index";
12-
import type { LiveReload as ActualLiveReload } from "../../ssr/components";
1312
import { RemixContext } from "../../ssr/components";
1413
import invariant from "../../ssr/invariant";
1514
import { RemixServer } from "../../ssr/server";
1615
import "@testing-library/jest-dom/extend-expect";
1716

18-
// TODO: Every time we touch LiveReload (without changing the API) these tests
19-
// fail, which tells me they're testing implementation details and not actual
20-
// behavior. Not sure how valuable they are. Disabling them until we can come up
21-
// with a better strategy for testing "developer workflow" things. An ideal
22-
// solution will let us fire up a development server, save a file, and observe
23-
// the browser reloads with the new UI. At the moment we could completely break
24-
// LiveReload's real features and these tests wouldn't know it.
25-
26-
describe("<LiveReload />", () => {
27-
let originalNodeEnv = process.env.NODE_ENV;
28-
afterEach(() => {
29-
process.env.NODE_ENV = originalNodeEnv;
30-
});
31-
32-
describe("non-development environment", () => {
33-
let LiveReload: typeof ActualLiveReload;
34-
beforeEach(() => {
35-
process.env.NODE_ENV = "not-development";
36-
jest.resetModules();
37-
LiveReload = require("../../ssr/components").LiveReload;
38-
});
39-
40-
it("does nothing if the NODE_ENV is not development", () => {
41-
let { container } = render(<LiveReload />);
42-
expect(container).toBeEmptyDOMElement();
43-
});
44-
});
45-
46-
describe("development environment", () => {
47-
let oldEnv = process.env;
48-
let LiveReload: typeof ActualLiveReload;
49-
beforeEach(() => {
50-
process.env = { ...oldEnv, NODE_ENV: "development" };
51-
jest.resetModules();
52-
});
53-
54-
it("defaults the origin to REMIX_DEV_ORIGIN env variable", () => {
55-
let origin = "http://test-origin";
56-
LiveReload = require("../../ssr/components").LiveReload;
57-
process.env = { ...oldEnv, REMIX_DEV_ORIGIN: origin };
58-
let { container } = render(<LiveReload />);
59-
expect(container.querySelector("script")).toHaveTextContent(
60-
`let LIVE_RELOAD_ORIGIN = ${JSON.stringify(origin)};`
61-
);
62-
});
63-
64-
it("can set the origin explicitly", () => {
65-
let origin = "http://test-origin";
66-
LiveReload = require("../../ssr/components").LiveReload;
67-
let { container } = render(<LiveReload origin={origin} />);
68-
expect(container.querySelector("script")).toHaveTextContent(
69-
`let LIVE_RELOAD_ORIGIN = ${JSON.stringify(origin)};`
70-
);
71-
});
72-
73-
it("defaults the port to 8002", () => {
74-
LiveReload = require("../../ssr/components").LiveReload;
75-
let { container } = render(<LiveReload />);
76-
expect(container.querySelector("script")).toHaveTextContent(
77-
"url.port = undefined || (LIVE_RELOAD_ORIGIN ? new URL(LIVE_RELOAD_ORIGIN).port : 8002);"
78-
);
79-
});
80-
81-
it("can set the port explicitly", () => {
82-
let { container } = render(<LiveReload port={4321} />);
83-
expect(container.querySelector("script")).toHaveTextContent(
84-
"url.port = 4321 || (LIVE_RELOAD_ORIGIN ? new URL(LIVE_RELOAD_ORIGIN).port : 8002);"
85-
);
86-
});
87-
88-
it("timeout of reload is set to 200ms", () => {
89-
LiveReload = require("../../ssr/components").LiveReload;
90-
let { container } = render(<LiveReload timeoutMs={200} />);
91-
expect(container.querySelector("script")).toHaveTextContent(
92-
"setTimeout( () => remixLiveReloadConnect({ onOpen: () => window.location.reload(), }), 200 );"
93-
);
94-
});
95-
});
96-
});
97-
9817
const setIntentEvents = ["focus", "mouseEnter", "touchStart"] as const;
9918
type PrefetchEventHandlerProps = {
10019
[Property in `on${Capitalize<(typeof setIntentEvents)[number]>}`]?: Function;

packages/react-router-dom/index.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -222,13 +222,7 @@ export {
222222
useRoutes,
223223
} from "react-router";
224224

225-
export {
226-
Meta,
227-
Links,
228-
Scripts,
229-
PrefetchPageLinks,
230-
LiveReload,
231-
} from "./ssr/components";
225+
export { Meta, Links, Scripts, PrefetchPageLinks } from "./ssr/components";
232226

233227
export type { HtmlLinkDescriptor } from "./ssr/links";
234228
export type {

packages/react-router-dom/ssr/components.tsx

Lines changed: 0 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,142 +1046,6 @@ export function useFetcher<TData = AppData>(
10461046
return useFetcherRR(opts);
10471047
}
10481048

1049-
/**
1050-
* This component connects your app to the Remix asset server and
1051-
* automatically reloads the page when files change in development.
1052-
* In production, it renders null, so you can safely render it always in your root route.
1053-
*
1054-
* @see https://remix.run/docs/components/live-reload
1055-
*/
1056-
export const LiveReload =
1057-
// Dead Code Elimination magic for production builds.
1058-
// This way devs don't have to worry about doing the NODE_ENV check themselves.
1059-
process.env.NODE_ENV !== "development"
1060-
? () => null
1061-
: function LiveReload({
1062-
origin,
1063-
port,
1064-
timeoutMs = 1000,
1065-
nonce = undefined,
1066-
}: {
1067-
origin?: string;
1068-
port?: number;
1069-
timeoutMs?: number;
1070-
nonce?: string;
1071-
}) {
1072-
// @ts-expect-error
1073-
let isViteClient = import.meta && import.meta.env !== undefined;
1074-
if (isViteClient) {
1075-
console.warn(
1076-
[
1077-
"`<LiveReload />` is obsolete when using Vite and can conflict with Vite's built-in HMR runtime.",
1078-
"",
1079-
"Remove `<LiveReload />` from your code and instead only use `<Scripts />`.",
1080-
"Then refresh the page to remove lingering scripts from `<LiveReload />`.",
1081-
].join("\n")
1082-
);
1083-
return null;
1084-
}
1085-
origin ??= process.env.REMIX_DEV_ORIGIN;
1086-
let js = String.raw;
1087-
return (
1088-
<script
1089-
nonce={nonce}
1090-
suppressHydrationWarning
1091-
dangerouslySetInnerHTML={{
1092-
__html: js`
1093-
function remixLiveReloadConnect(config) {
1094-
let LIVE_RELOAD_ORIGIN = ${JSON.stringify(origin)};
1095-
let protocol =
1096-
LIVE_RELOAD_ORIGIN ? new URL(LIVE_RELOAD_ORIGIN).protocol.replace(/^http/, "ws") :
1097-
location.protocol === "https:" ? "wss:" : "ws:"; // remove in v2?
1098-
let hostname = LIVE_RELOAD_ORIGIN ? new URL(LIVE_RELOAD_ORIGIN).hostname : location.hostname;
1099-
let url = new URL(protocol + "//" + hostname + "/socket");
1100-
1101-
url.port =
1102-
${port} ||
1103-
(LIVE_RELOAD_ORIGIN ? new URL(LIVE_RELOAD_ORIGIN).port : 8002);
1104-
1105-
let ws = new WebSocket(url.href);
1106-
ws.onmessage = async (message) => {
1107-
let event = JSON.parse(message.data);
1108-
if (event.type === "LOG") {
1109-
console.log(event.message);
1110-
}
1111-
if (event.type === "RELOAD") {
1112-
console.log("💿 Reloading window ...");
1113-
window.location.reload();
1114-
}
1115-
if (event.type === "HMR") {
1116-
if (!window.__hmr__ || !window.__hmr__.contexts) {
1117-
console.log("💿 [HMR] No HMR context, reloading window ...");
1118-
window.location.reload();
1119-
return;
1120-
}
1121-
if (!event.updates || !event.updates.length) return;
1122-
let updateAccepted = false;
1123-
let needsRevalidation = new Set();
1124-
for (let update of event.updates) {
1125-
console.log("[HMR] " + update.reason + " [" + update.id +"]")
1126-
if (update.revalidate) {
1127-
needsRevalidation.add(update.routeId);
1128-
console.log("[HMR] Revalidating [" + update.routeId + "]");
1129-
}
1130-
let imported = await import(update.url + '?t=' + event.assetsManifest.hmr.timestamp);
1131-
if (window.__hmr__.contexts[update.id]) {
1132-
let accepted = window.__hmr__.contexts[update.id].emit(
1133-
imported
1134-
);
1135-
if (accepted) {
1136-
console.log("[HMR] Update accepted by", update.id);
1137-
updateAccepted = true;
1138-
}
1139-
}
1140-
}
1141-
if (event.assetsManifest && window.__hmr__.contexts["remix:manifest"]) {
1142-
let accepted = window.__hmr__.contexts["remix:manifest"].emit(
1143-
{ needsRevalidation, assetsManifest: event.assetsManifest }
1144-
);
1145-
if (accepted) {
1146-
console.log("[HMR] Update accepted by", "remix:manifest");
1147-
updateAccepted = true;
1148-
}
1149-
}
1150-
if (!updateAccepted) {
1151-
console.log("[HMR] Update rejected, reloading...");
1152-
window.location.reload();
1153-
}
1154-
}
1155-
};
1156-
ws.onopen = () => {
1157-
if (config && typeof config.onOpen === "function") {
1158-
config.onOpen();
1159-
}
1160-
};
1161-
ws.onclose = (event) => {
1162-
if (event.code === 1006) {
1163-
console.log("Remix dev asset server web socket closed. Reconnecting...");
1164-
setTimeout(
1165-
() =>
1166-
remixLiveReloadConnect({
1167-
onOpen: () => window.location.reload(),
1168-
}),
1169-
${String(timeoutMs)}
1170-
);
1171-
}
1172-
};
1173-
ws.onerror = (error) => {
1174-
console.log("Remix dev asset server web socket error:");
1175-
console.error(error);
1176-
};
1177-
}
1178-
remixLiveReloadConnect();
1179-
`,
1180-
}}
1181-
/>
1182-
);
1183-
};
1184-
11851049
export function mergeRefs<T = any>(
11861050
...refs: Array<React.MutableRefObject<T> | React.LegacyRef<T>>
11871051
): React.RefCallback<T> {

0 commit comments

Comments
 (0)