Skip to content

fix(404): handle nested package routing#72

Merged
paoloricciuti merged 7 commits into
e18e:mainfrom
jdebarochez:fix-nested-error-page
May 27, 2026
Merged

fix(404): handle nested package routing#72
paoloricciuti merged 7 commits into
e18e:mainfrom
jdebarochez:fix-nested-error-page

Conversation

@jdebarochez
Copy link
Copy Markdown
Contributor

@jdebarochez jdebarochez commented May 24, 2026

Hello 👋

In order to fix #71 , I'm attempting my first contribution:

Looking at the code, we miss a default +error.svelte page. In order to not duplicate the existing 404 displayed error when mapping is empty, I've decided to throw the error when data is loaded. This has the benefits to avoid conditions in src/routes/[[scope=scope]]/[package]/+page.svelte.

Let me know what should be improved, I'm not a Svelte expert. 🙏

* add a default +error.svelte page
* refactor existing 404 logic in load to have an explicit error
let mapping = $derived(
Object.hasOwn(all.mappings, package_name) ? all.mappings[package_name] : undefined
);
let mapping = $derived(all.mappings[package_name]);
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.

this was on purpose because package_name is user input

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'm not sure I get your comment. It's also the URL parameter: params.package. What issue do you see and I don't @43081j ?

Copy link
Copy Markdown
Contributor

@gameroman gameroman May 24, 2026

Choose a reason for hiding this comment

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

I think this was for security (__proto__)?

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.

that this was specifically using Object.hasOwn before for security reasons.

this PR doesn't need to change it

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.

OK, clear! That's where my Svelte knowledge ran short. I was expecting the load function to make sure of it. Let me revert that change then. 👍

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.

@43081j I reverted the change. Now we can get null reference exception. What do you think?

@43081j
Copy link
Copy Markdown
Contributor

43081j commented May 25, 2026

i'm going to wait for @paoloricciuti to review this one.

it seems the template has changed to drop the if/else, then an error page has been added. but i feel like we should be able to solve this by just adding the error page.

im just not sure and really Paolo needs to review this.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We were using the +page.ts to set prerender = false but to load the data we are using the much more ergonomic remote functions...also this logic should really be a param matcher not a load function

Comment thread src/routes/+error.svelte
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I always need to refresh my knowledgeable on error pages (shame on me) but I'm pretty sure we can use a single error page for both paths by moving it in the common ancestor. Will check tomorrow

@jdebarochez
Copy link
Copy Markdown
Contributor Author

Hello @paoloricciuti 👋

I have no hard feeling on this PR. If you have a simpler solution, go for it. I don't want you to waste your time on mine. 😅

@paoloricciuti
Copy link
Copy Markdown
Collaborator

@jdebarochez @43081j I pushed something that should work! Let me know what you think.

@paoloricciuti
Copy link
Copy Markdown
Collaborator

Had to do a couple more fix because I didn't anticipate a change in the page reflecting on the remote function. Now it should work

@paoloricciuti paoloricciuti merged commit 738c45c into e18e:main May 27, 2026
@paoloricciuti
Copy link
Copy Markdown
Collaborator

Thanks @jdebarochez 🧡

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.

Broken layout on nested 404 pages

4 participants