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

new defineRouter #949

Merged
merged 11 commits into from
Oct 10, 2024
Merged

new defineRouter #949

merged 11 commits into from
Oct 10, 2024

Conversation

dai-shi
Copy link
Owner

@dai-shi dai-shi commented Oct 5, 2024

We would like to redesign defineRouter. This is why we have unstable_ prefix.

#885 (comment)

similar snippets in both defineRouter and createPages are currently assuming 1:1 relationship from path to component id.

That's the exactly one of the reasons. It shouldn't be 1:1. It can be anything, and it can cache each. This will change waku/router/client too including "shouldSkipList".

Starting with a rough idea.

Copy link

vercel bot commented Oct 5, 2024

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

Name Status Preview Updated (UTC)
waku ✅ Ready (Inspect) Visit Preview Oct 9, 2024 11:55pm

Copy link

codesandbox-ci bot commented Oct 5, 2024

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.

Copy link
Contributor

@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.

Overall, I think the new defineRouter implementation reads really well!

This really helps to see what you meant by simplifying the structures in the previous version.

export function NewServerRouter({ route }: { route: RouteProps }) {
const routeElement = createElement(Slot, { id: getRouteSlotId(route.path) });
return createElement(
Fragment,
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the purpose of this Fragment?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Maybe, it's to match the component tree with NewRouter. If removing it works, we can remove it. TBH, I don't like NewServerRouter hack. I wish just NewRouter worked.

return fetchRsc(encodeRoutePath('/404'));
}
const data = createData(responsePromise);
Promise.resolve(data)
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this resolve the responsePromise twice? First on L772 then again here? Or is my understanding off with that?

then if it does resolve twice, shouldn't createData just use response?

Copy link
Owner Author

Choose a reason for hiding this comment

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

createData requires a promise, so L772 isn't related with L780.

However, yes, data.then((date) => here might work. The reason I added Promise.resolve() is because data returned by createData isn't a real promise. TS types aren't correct here. So, it's just a safe bet. Maybe it's not necessary.

@@ -0,0 +1,156 @@
import { new_defineRouter } from 'waku/router/server';
import { Slot, Children } from 'waku/client';
Copy link
Contributor

Choose a reason for hiding this comment

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

is waku/client the best place for these? client to me would mean these are targeted towards the scope of client components, but they're just used here for the router to be able to target where to replace with each level of rendering components (regardless of client vs server)

that is if I understand correctly

Copy link
Owner Author

Choose a reason for hiding this comment

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

They are client components. We can embed client components in a server component. It's confusing, but it's how it works. createPages API will hide this complexity anyway.

@dai-shi dai-shi marked this pull request as ready for review October 9, 2024 23:28
@dai-shi dai-shi merged commit e2a2bc4 into main Oct 10, 2024
24 checks passed
@dai-shi dai-shi deleted the idea/new-define-router branch October 10, 2024 00:35
@dai-shi dai-shi mentioned this pull request Oct 12, 2024
@dai-shi dai-shi changed the title idea: new defineRouter new defineRouter Oct 12, 2024
dai-shi added a commit that referenced this pull request Dec 8, 2024
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.

2 participants