Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug?]: Issues with API/component routes in routes with parameters in RC1 #1470

Closed
2 tasks done
timothyallan opened this issue May 7, 2024 · 3 comments
Closed
2 tasks done
Labels
bug Something isn't working

Comments

@timothyallan
Copy link

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior 😯

This probably needs a new issue as it's parameter based routes now, not route groups like #1463

Just got the RC1 installed, and this is still an issue, but it seems related to route params now, not route groups anymore. I narrowed it down some more to a route with a parameter in it.

Expected behavior 🤔

should be able to access both routes

Steps to reproduce 🕹

Minimal repro is this structure:
Screenshot 2024-05-06 at 2 22 01 PM

Where (viewer).tsx is just

export default function Viewer() {
  return <div>Viewer</div>;
}

and thumbnail.tsx is

import { APIEvent } from '@solidjs/start/server';

export async function GET({ request }: APIEvent) {
  console.log(`getting the thumbnail`);
}

Navigate to anything like http://localhost:3000/viewer/abc
As long as that API route in there, there's a 500. As soon as thumbnail.tsx is removed, that route works.

[h3] [unhandled] TypeError: Cannot read properties of undefined (reading '$GET')
    at Module.matchAPIRoute (/test/solid-project/node_modules/@solidjs/start/dist/router/routes.js:32:32)

Context 🔦

No response

Your environment 🌎

No response

@timothyallan timothyallan added the bug Something isn't working label May 7, 2024
@timothyallan timothyallan changed the title [Bug?]: [Bug?]: Issues with API/component routes in routes with parameters in RC1 May 7, 2024
@ryansolid
Copy link
Member

I'm going to ask for a reproduction on this one. I have an example similar to this in the experiments and it seems to be working when I add an API route in it. I also tried to reproduce something what you shared and didn't have any issue. Only other thing I could think of is make sure your GET method returns something. We do pass through if it misses. Not sure if that is related but I'd start there. Having your console.log in your example didn't error for me though.. just returned an empty page.

@timothyallan
Copy link
Author

timothyallan commented May 8, 2024

Yep, no problem. What I did:

  • npm init solid@latest with new basic typescript project
  • npm install
  • created the 2 files in the same structure as the initial image above
  • npm run dev
  • navigate to http://localhost:3000/viewer/abc and get a 500
  • move/delete thumbnails.tsx, reload, the route works with the proper param picked up.

Here's the result of that:
solid-project.zip

Edit: also changed the GET to return something, same result.

@ryansolid
Copy link
Member

Thanks I see it. It's odd. The router matches for API when I wouldn't expect it to. Any case added the null check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants