Skip to content

Conversation

hamlim
Copy link
Contributor

@hamlim hamlim commented May 31, 2025

This change sorts the path configs returned from the getConfig method passed to unstable_defineRouter within createPages, specifically sorting wildcard routes to the end of the list of path configs.

Additionally this PR adds a previously failing e2e test for #1448, which now passes after the change.

Fixes: #1448

Copy link

vercel bot commented May 31, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
waku ✅ Ready (Inspect) Visit Preview Jun 25, 2025 0:34am
Copy link

codesandbox-ci bot commented May 31, 2025

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@dai-shi dai-shi mentioned this pull request May 28, 2025
@hamlim
Copy link
Contributor Author

hamlim commented Jun 5, 2025

Figured I'd try to implement a fix also, pushed a change here: 0805f30 to sort wildcard path configs to the end of the array so we match on them last.

Not sure if this is a naive fix (and maybe leads to other issues), but it seems to make the most sense in that we should probably match explicit path specs first before falling back on wildcard route segments.

cc @tylersayshi

@hamlim hamlim changed the title Add E2E test for wildcard route interception API route request Jun 5, 2025
@hamlim hamlim marked this pull request as ready for review June 5, 2025 21:15
Copy link
Member

@dai-shi dai-shi left a comment

Choose a reason for hiding this comment

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

Not sure if this is a naive fix (and maybe leads to other issues), but it seems to make the most sense in that we should probably match explicit path specs first before falling back on wildcard route segments.

It might make sense, but I would like to leave this responsibility for create-pages.ts. Can you modify create-pages.ts instead of define-router.ts?

@hamlim
Copy link
Contributor Author

hamlim commented Jun 6, 2025

@dai-shi got some time to take a look at the code again today - I don't think this can be solved for within create-pages.ts as the code is today. There's no exposed hook within defineRouter that allows create-pages to sort the complete list of path specs or to choose the matching path config.

One possible option could be to have defineRouter allow for integrations to pass in a custom getPathConfigItem function (keep the current implementation as a default parameter, maybe tweak it slightly to call getPathConfigItem with the pathConfig and the existing pathname argument), then create-pages could pass in a custom method to sort the list of path configs and then return a .find for the path. Would that change make more sense?

After thinking about my naive solve here a bit more, an even simpler solve could be to move the api route spread here up above the page route spread.

@dai-shi
Copy link
Member

dai-shi commented Jun 7, 2025

Ah I see what you mean. I think we should make some changes in define-router.ts. I can work on it later but not soon.

@dai-shi
Copy link
Member

dai-shi commented Jun 17, 2025

I can work on it later but not soon.

I haven't started. Give me time.

@dai-shi
Copy link
Member

dai-shi commented Jun 22, 2025

I haven't started. Give me time.

👉 #1487

dai-shi added a commit that referenced this pull request Jun 23, 2025
Technically breaking change for unstable defineRouter.

Related: #1451
@hamlim hamlim requested a review from dai-shi June 23, 2025 15:10
Copy link
Member

@dai-shi dai-shi left a comment

Choose a reason for hiding this comment

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

@hamlim I'm sorry, but you seem to forget our previous conversation. #1451 (review)

The fix should be in create-pages.ts. Do not modify define-router.ts.

@hamlim hamlim changed the title Fix(define-router): Fix path matching precedence for api routes with wildcard routes Jun 24, 2025
@hamlim
Copy link
Contributor Author

hamlim commented Jun 24, 2025

Sorry about that, updated the branch to apply the fix in create-pages instead!

If defineRouter will be more of a stable public API in the long run - we may want to consider documenting this quirk to let folks know that this issue may happen if they're not using the create-pages setup - but that can be done in a future change

@dai-shi
Copy link
Member

dai-shi commented Jun 24, 2025

Record of flaky tests:

https://github.com/wakujs/waku/actions/runs/15853235995/job/44691999735?pr=1451

Error: 1) [chromium-prd] › e2e/ssg-performance.spec.ts:17:3 › high volume static site generation › build and verify
Test timeout of 60000ms exceeded.

https://github.com/wakujs/waku/actions/runs/15853235995/job/44691999777?pr=1451

Error: 1) [chromium-prd] › e2e\ssg-performance.spec.ts:17:3 › high volume static site generation › build and verify
Test timeout of 60000ms exceeded.

Copy link
Member

@dai-shi dai-shi left a comment

Choose a reason for hiding this comment

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

LGTM

@tylersayshi Can you have another review?

Copy link
Member

@tylersayshi tylersayshi left a comment

Choose a reason for hiding this comment

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

rest looks good 👍

Copy link
Member

@dai-shi dai-shi left a comment

Choose a reason for hiding this comment

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

LGTM

@dai-shi dai-shi merged commit be5fdb6 into wakujs:main Jun 25, 2025
26 checks passed
@hamlim
Copy link
Contributor Author

hamlim commented Jun 25, 2025

Thanks for all the reviews and feedback!

@hamlim hamlim deleted the e2e-catch-all-overriding-api-routes branch June 25, 2025 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants