Skip to content

Commit

Permalink
Update to use renamed patchRoutesOnNavigation function
Browse files Browse the repository at this point in the history
  • Loading branch information
brophdawg11 committed Aug 14, 2024
1 parent df3cdc8 commit bafa806
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 70 deletions.
3 changes: 2 additions & 1 deletion .changeset/shy-ducks-repeat.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"@remix-run/server-runtime": patch
---

Fog of War: Simplify implementation now that React Router handles slug/splat edge cases and tracks previously disscovered routes (see https://github.com/remix-run/react-router/pull/11883)
- Fog of War: Simplify implementation now that React Router handles slug/splat edge cases and tracks previously disscovered routes (see https://github.com/remix-run/react-router/pull/11883)
- This changes the return signature of the internal `__manifest` endpoint since we no longer need the `notFoundPaths` field
- Fog of War: Update to use renamed `unstable_patchRoutesOnNavigation` function in RR (see https://github.com/remix-run/react-router/pull/11888)
2 changes: 1 addition & 1 deletion integration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@remix-run/dev": "workspace:*",
"@remix-run/express": "workspace:*",
"@remix-run/node": "workspace:*",
"@remix-run/router": "0.0.0-experimental-dc307bdd5",
"@remix-run/router": "0.0.0-experimental-5a6545bf7",
"@remix-run/server-runtime": "workspace:*",
"@types/express": "^4.17.9",
"@vanilla-extract/css": "^1.10.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/remix-dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@mdx-js/mdx": "^2.3.0",
"@npmcli/package-json": "^4.0.1",
"@remix-run/node": "workspace:*",
"@remix-run/router": "0.0.0-experimental-dc307bdd5",
"@remix-run/router": "0.0.0-experimental-5a6545bf7",
"@remix-run/server-runtime": "workspace:*",
"@types/mdx": "^2.0.5",
"@vanilla-extract/integration": "^6.2.0",
Expand Down
23 changes: 11 additions & 12 deletions packages/remix-react/browser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ import {
getSingleFetchDataStrategy,
} from "./single-fetch";
import invariant from "./invariant";
import { initFogOfWar, useFogOFWarDiscovery } from "./fog-of-war";
import {
getPatchRoutesOnNavigationFunction,
useFogOFWarDiscovery,
} from "./fog-of-war";

/* eslint-disable prefer-let/prefer-let */
declare global {
Expand Down Expand Up @@ -305,14 +308,6 @@ export function RemixBrowser(_props: RemixBrowserProps): ReactElement {
}
}

let { enabled: isFogOfWarEnabled, patchRoutesOnMiss } = initFogOfWar(
window.__remixManifest,
window.__remixRouteModules,
window.__remixContext.future,
window.__remixContext.isSpaMode,
window.__remixContext.basename
);

// We don't use createBrowserRouter here because we need fine-grained control
// over initialization to support synchronous `clientLoader` flows.
router = createRouter({
Expand All @@ -337,9 +332,13 @@ export function RemixBrowser(_props: RemixBrowserProps): ReactElement {
window.__remixRouteModules
)
: undefined,
...(isFogOfWarEnabled
? { unstable_patchRoutesOnMiss: patchRoutesOnMiss }
: {}),
unstable_patchRoutesOnNavigation: getPatchRoutesOnNavigationFunction(
window.__remixManifest,
window.__remixRouteModules,
window.__remixContext.future,
window.__remixContext.isSpaMode,
window.__remixContext.basename
),
});

// We can call initialize() immediately if the router doesn't have any
Expand Down
41 changes: 17 additions & 24 deletions packages/remix-react/fog-of-war.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Router } from "@remix-run/router";
import { matchRoutes } from "@remix-run/router";
import * as React from "react";
import type { unstable_PatchRoutesOnMissFunction } from "react-router";
import type { unstable_PatchRoutesOnNavigationFunction } from "react-router";

import type { AssetsManifest, FutureConfig } from "./entry";
import type { RouteModules } from "./routeModules";
Expand Down Expand Up @@ -64,36 +64,29 @@ export function getPartialManifest(manifest: AssetsManifest, router: Router) {
};
}

export function initFogOfWar(
export function getPatchRoutesOnNavigationFunction(
manifest: AssetsManifest,
routeModules: RouteModules,
future: FutureConfig,
isSpaMode: boolean,
basename: string | undefined
): {
enabled: boolean;
patchRoutesOnMiss?: unstable_PatchRoutesOnMissFunction;
} {
): unstable_PatchRoutesOnNavigationFunction | undefined {
if (!isFogOfWarEnabled(future, isSpaMode)) {
return { enabled: false };
return undefined;
}

return {
enabled: true,
patchRoutesOnMiss: async ({ path, patch }) => {
if (discoveredPaths.has(path)) {
return;
}
await fetchAndApplyManifestPatches(
[path],
manifest,
routeModules,
future,
isSpaMode,
basename,
patch
);
},
return async ({ path, patch }) => {
if (discoveredPaths.has(path)) {
return;
}
await fetchAndApplyManifestPatches(
[path],
manifest,
routeModules,
future,
isSpaMode,
basename,
patch
);
};
}

Expand Down
6 changes: 3 additions & 3 deletions packages/remix-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
"tsc": "tsc"
},
"dependencies": {
"@remix-run/router": "0.0.0-experimental-dc307bdd5",
"@remix-run/router": "0.0.0-experimental-5a6545bf7",
"@remix-run/server-runtime": "workspace:*",
"react-router": "0.0.0-experimental-dc307bdd5",
"react-router-dom": "0.0.0-experimental-dc307bdd5",
"react-router": "0.0.0-experimental-5a6545bf7",
"react-router-dom": "0.0.0-experimental-5a6545bf7",
"turbo-stream": "2.3.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/remix-server-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"tsc": "tsc"
},
"dependencies": {
"@remix-run/router": "0.0.0-experimental-dc307bdd5",
"@remix-run/router": "0.0.0-experimental-5a6545bf7",
"@types/cookie": "^0.6.0",
"@web3-storage/multipart-parser": "^1.0.0",
"cookie": "^0.6.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/remix-testing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
"dependencies": {
"@remix-run/node": "workspace:*",
"@remix-run/react": "workspace:*",
"@remix-run/router": "0.0.0-experimental-dc307bdd5",
"react-router-dom": "0.0.0-experimental-dc307bdd5"
"@remix-run/router": "0.0.0-experimental-5a6545bf7",
"react-router-dom": "0.0.0-experimental-5a6545bf7"
},
"devDependencies": {
"@remix-run/server-runtime": "workspace:*",
Expand Down
50 changes: 25 additions & 25 deletions pnpm-lock.yaml

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

0 comments on commit bafa806

Please sign in to comment.