@@ -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-
11851049export function mergeRefs < T = any > (
11861050 ...refs : Array < React . MutableRefObject < T > | React . LegacyRef < T > >
11871051) : React . RefCallback < T > {
0 commit comments