Skip to content

Commit e2d0624

Browse files
authored
fix: do not skip app-wrapper for sibling routes (#2911)
This PR adds a unit test for the issue in #2910. I have not found a solution yet, since I'm not very familiar with the `fsRoutes` code, and what it is doing. But a thought a unit test with the failing code could help to find a bug fix. **Edit:** I managed to fix the failing test by removing a couple of lines, but I'm not too familiar with the code so I'm not sure if it's correct. It seems to pass all the tests still... Closes #2910
1 parent f15f225 commit e2d0624

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

src/plugins/fs_routes/mod.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,10 @@ export async function fsRoutes<State>(
221221

222222
// _app template
223223
if (skipApp && mod.path === "/_app") {
224-
hasApp = false;
225224
continue;
226225
} else if (!skipApp && mod.config?.skipAppWrapper) {
227226
skipApp = true;
228227
if (hasApp) {
229-
hasApp = false;
230228
// _app component is always first
231229
components.shift();
232230
}

src/plugins/fs_routes/mod_test.tsx

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,56 @@ Deno.test("fsRoutes - route overrides _app", async () => {
558558
expect(doc.body.firstChild?.textContent).toEqual("route");
559559
});
560560

561+
Deno.test("fsRoutes - route overrides _app does not affect other routes", async () => {
562+
const server = await createServer({
563+
"routes/_500.tsx": {
564+
config: { skipInheritedLayouts: true },
565+
default: () => <>error!</>,
566+
},
567+
"routes/_app.tsx": {
568+
default: (ctx) => (
569+
<div>
570+
app/<ctx.Component />
571+
</div>
572+
),
573+
},
574+
"routes/_layout.tsx": {
575+
default: (ctx) => (
576+
<>
577+
layout/<ctx.Component />
578+
</>
579+
),
580+
},
581+
// By having "bar" come before "foo", this results in a bug
582+
// where the app wrapper is missing from "foo".
583+
"routes/bar.tsx": {
584+
config: {
585+
skipAppWrapper: true,
586+
skipInheritedLayouts: true,
587+
},
588+
default: () => <>bar</>,
589+
},
590+
"routes/index.tsx": { default: () => <>index</> },
591+
"routes/foo.tsx": { default: () => <>foo</> },
592+
});
593+
594+
const [indexRes, fooRes, barRes] = await Promise.all([
595+
server.get("/"),
596+
server.get("/foo"),
597+
server.get("/bar"),
598+
]);
599+
const [index, foo, bar] = await Promise.all([
600+
indexRes.text(),
601+
fooRes.text(),
602+
barRes.text(),
603+
]);
604+
expect(parseHtml(index).body.firstChild?.textContent).toEqual(
605+
"app/layout/index",
606+
);
607+
expect(parseHtml(foo).body.firstChild?.textContent).toEqual("app/layout/foo");
608+
expect(parseHtml(bar).body.firstChild?.textContent).toEqual("bar");
609+
});
610+
561611
Deno.test("fsRoutes - handler return data", async () => {
562612
const server = await createServer({
563613
"routes/index.tsx": {

0 commit comments

Comments
 (0)