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

fix: new_defineRouter #991

Merged
merged 5 commits into from
Nov 8, 2024
Merged

fix: new_defineRouter #991

merged 5 commits into from
Nov 8, 2024

Conversation

dai-shi
Copy link
Owner

@dai-shi dai-shi commented Nov 7, 2024

No description provided.

Copy link

vercel bot commented Nov 7, 2024

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

Name Status Preview Updated (UTC)
waku ✅ Ready (Inspect) Visit Preview Nov 8, 2024 6:21am

Copy link

codesandbox-ci bot commented Nov 7, 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.

@dai-shi dai-shi marked this pull request as ready for review November 7, 2024 13:51
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.

lgtm 👍

Comment on lines 407 to 411
for (const skipId of skip) {
if (await canSkip(pathname, skipId)) {
delete entries[skipId];
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
for (const skipId of skip) {
if (await canSkip(pathname, skipId)) {
delete entries[skipId];
}
}
const toSkip = await Promise.all(skip.map((skipId) => canSkip(pathname, skipId));
for (const skipId of toSkip) {
delete entries[skipId];
}

Copy link
Owner Author

Choose a reason for hiding this comment

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

Do you mean filter instead of map?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, thanks!

Copy link
Owner Author

Choose a reason for hiding this comment

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

canSkip also waits only a microtask. If we were to improve it, there must be a better way. So, l'd leave it for now.

Comment on lines +398 to +402
if (
Object.keys(elements).some((id) => id.startsWith(ROUTE_SLOT_ID_PREFIX))
) {
throw new Error('Element ID cannot start with "route:"');
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this check needed if you're moving to use routeElement also?

Copy link
Owner Author

Choose a reason for hiding this comment

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

This is needed to avoid conflict because we move to routeElement.

pathname: string,
slotId: SlotId,
): Promise<boolean> => {
const pathConfig = await getMyPathConfig();
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, should canSkip take the result of getMyPathConfig() as a parameter? It seems unnecessary to await it for every pathname checked.

Copy link
Owner Author

Choose a reason for hiding this comment

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

it's possible. await just waits one microtask in this case, so I didn't care much.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok!

Copy link
Owner Author

Choose a reason for hiding this comment

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

I don't disagree it's not ideal and there is room for improvement. Let's revisit it later as we will be rewriting this anyway.

return processSkip({
'route:/nested/baz': (
return {
routeElement: (
Copy link
Contributor

Choose a reason for hiding this comment

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

nice! what made you change your mind on this?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Do you mean moving skip handling from outside to inside? It's clearer abstraction.
The drawback is that now the user of new_defineRouter doesn't have "skip" information, they can't optimize based on it. (They have to return elements that will be skipped. So, theoretically, it's the waste.)

Copy link
Contributor

Choose a reason for hiding this comment

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

thanks, ya that makes sense

@dai-shi dai-shi merged commit 75c9884 into main Nov 8, 2024
26 checks passed
@dai-shi dai-shi deleted the fix/new-define-router branch November 8, 2024 08:08
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