Skip to content

Commit

Permalink
Support basename
Browse files Browse the repository at this point in the history
  • Loading branch information
brophdawg11 committed Jun 11, 2024
1 parent 7800ea0 commit 21befc9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
12 changes: 8 additions & 4 deletions packages/remix-react/browser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ export function RemixBrowser({
if (!known404Paths.has(path)) {
await fetchAndApplyManifestPatches(
[path],
window.__remixContext.basename,
window.__remixManifest.version,
patch
);
Expand Down Expand Up @@ -422,7 +423,7 @@ export function RemixBrowser({
async function fetchPatches() {
fogOfWarAbortControllerRef.current?.abort();

let lazyPaths = getFogOfWarPaths();
let lazyPaths = getFogOfWarPaths(window.__remixContext.basename);
if (lazyPaths.length === 0) {
return;
}
Expand All @@ -431,6 +432,7 @@ export function RemixBrowser({
fogOfWarAbortControllerRef.current = new AbortController();
await fetchAndApplyManifestPatches(
lazyPaths,
window.__remixContext.basename,
window.__remixManifest.version,
router.patchRoutes,
fogOfWarAbortControllerRef.current.signal
Expand Down Expand Up @@ -515,7 +517,7 @@ export function RemixBrowser({
);
}

function getFogOfWarPaths() {
function getFogOfWarPaths(basename: string | undefined) {
return Array.from(nextPaths.keys()).filter((path) => {
if (knownGoodPaths.has(path)) {
nextPaths.delete(path);
Expand All @@ -527,7 +529,7 @@ function getFogOfWarPaths() {
return false;
}

let matches = matchRoutes(router.routes, path);
let matches = matchRoutes(router.routes, path, basename);
if (matches) {
knownGoodPaths.add(path);
nextPaths.delete(path);
Expand All @@ -540,11 +542,13 @@ function getFogOfWarPaths() {

async function fetchAndApplyManifestPatches(
paths: string[],
basename: string | undefined,
version: string,
patchRoutes: Router["patchRoutes"],
signal?: AbortSignal
): Promise<void> {
let url = new URL("/__manifest", window.location.origin);
let manifestPath = `${basename ?? "/"}/__manifest`.replace(/\/+/g, "/");
let url = new URL(manifestPath, window.location.origin);
url.searchParams.set("version", version);
paths.forEach((path) => url.searchParams.append("paths", path));
let data = (await fetch(url, { signal }).then((res) => res.json())) as {
Expand Down
7 changes: 6 additions & 1 deletion packages/remix-server-runtime/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,12 @@ export const createRequestHandler: CreateRequestHandlerFunction = (
};

// Manifest request for fog of war
if (url.pathname === "/__manifest") {

let manifestUrl = `${_build.basename ?? "/"}/__manifest`.replace(
/\/+/g,
"/"
);
if (url.pathname === manifestUrl) {
try {
let res = await handleManifestRequest(_build, routes, url);
return res;
Expand Down

0 comments on commit 21befc9

Please sign in to comment.