Skip to content

fix: do not skip app-wrapper for sibling routes#2911

Merged
marvinhagemeister merged 2 commits into
freshframework:mainfrom
csvn:test/add-failing-app-test
May 13, 2025
Merged

fix: do not skip app-wrapper for sibling routes#2911
marvinhagemeister merged 2 commits into
freshframework:mainfrom
csvn:test/add-failing-app-test

Conversation

@csvn

@csvn csvn commented May 10, 2025

Copy link
Copy Markdown
Contributor

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

Comment on lines +581 to +589
// By having "bar" come before "foo", this results in a bug
// where the app wrapper is missing from "foo".
"routes/bar.tsx": {
config: {
skipAppWrapper: true,
skipInheritedLayouts: true,
},
default: () => <>bar</>,
},

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If route/bar.tsx came after routes/foo.tsx in the record, the issue disappears. Since iteration over the files happens in key-order (for test method createServer) it seems to be some connection to the order FS will walk over the directory for this issue to occur in a real app.

@csvn csvn force-pushed the test/add-failing-app-test branch from b707f30 to d48df03 Compare May 12, 2025 21:39
@csvn csvn changed the title test: add app-wrapper test for sibling config routes fix: do not skip app-wrapper for sibling routes May 12, 2025
@csvn csvn force-pushed the test/add-failing-app-test branch from d48df03 to c484500 Compare May 12, 2025 21:46
Comment on lines 223 to 229
if (skipApp && mod.path === "/_app") {
hasApp = false;
continue;
} else if (!skipApp && mod.config?.skipAppWrapper) {
skipApp = true;
if (hasApp) {
hasApp = false;
// _app component is always first
components.shift();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if it's correct just to remove these lines. It looks wrong to me to set hasApp to false if we're looping over every route, since a latter route may have the app wrapper disabled always.

This change makes the test I added pass anyway...

@csvn

csvn commented May 12, 2025

Copy link
Copy Markdown
Contributor Author

@marvinhagemeister I think this PR is ready for review. I don't see any failing tests, and it looks like the test I added now passes so this should likely fix #2910 too.

@marvinhagemeister marvinhagemeister left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch! Seems like always setting hasApp = false was a bit heavy handed. Happy to hear that this was all that's needed to fix it 👍

@marvinhagemeister

Copy link
Copy Markdown
Contributor

Ah wait kinda wondering if there is a case where a route says to skip the app wrapper, but the next route in the list doesn't. In that case we need to ensure that the app wrapper template is still applied.

@csvn

csvn commented May 13, 2025

Copy link
Copy Markdown
Contributor Author

Ah wait kinda wondering if there is a case where a route says to skip the app wrapper, but the next route in the list doesn't. In that case we need to ensure that the app wrapper template is still applied.

I think that's exactly what I tried to accomplish with my change? To me skipApp is used for that, and hasApp is whether or not an _app file exists at all. I don't think "_app exists" should ever be changed after set to true.

  • After my changes, hasApp is initialized to false, and only ever changes once to true if /_app is encountered.
  • Nested for loops are running over two route modules, and routeMod seems to be all routes, and mod the current "special" route (e.g. _app, _layout etc)
    • skipApp (let skipApp = !!routeMod.config?.skipAppWrapper;) and mod.config?.skipAppWrapper, are these ones together not enough to determine if the app wrapper should be included?
  • I don't really understand what the components.shift() part does 😅

It at least looks off to me if hasApp is set to false, because if routes 1, 2 and 3 are processed in that order, if 1 uses skipAppWrapper: true, then hasApp becomes false and 2 and 3 can never have the app-wrapper.

Not sure I understood your question. But I don't think I've dug into fs_routes/mod.ts enough to understand it more than that. 🤔

@csvn

csvn commented May 13, 2025

Copy link
Copy Markdown
Contributor Author

Perhaps hasApp could be renamed appRouteExists, and useAppWrapper/useAppComponent instead of skipApp. Maybe that would make it clearer? I think it should likely be enough to only ever change skipApp in current for loop, because no other route should be able to make permanent changes to another route?

@marvinhagemeister

Copy link
Copy Markdown
Contributor

Ah you're totally right. I confused hasApp with skipApp, I guess a sign that more distinct names would be better 😅

@marvinhagemeister marvinhagemeister merged commit e2d0624 into freshframework:main May 13, 2025
7 checks passed
@csvn csvn deleted the test/add-failing-app-test branch May 13, 2025 16:56
@csvn

csvn commented May 13, 2025

Copy link
Copy Markdown
Contributor Author

@marvinhagemeister there's been quite a few fixes and changes in the last few weeks. Would it be possible to release a new Alpha version soon? The last release was in January, and it would be nice to test out some of the recent bug-fixes with a new JSR release 🙏 😇

(No pressure though 😁)

@marvinhagemeister

Copy link
Copy Markdown
Contributor

@csvn yep, released alpha 30 earlier today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

App wrapper not rendered for sibling route

2 participants