-
Notifications
You must be signed in to change notification settings - Fork 46
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
feat: $
prefix named file as island component
#171
Conversation
Hey @usualoma ! What do you think about this? If it's okay, please review it! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is a good idea. I agree!
I have made one comment, please confirm.
src/vite/island-components.ts
Outdated
*/ | ||
export function matchIslandComponentId(id: string) { | ||
return id.match( | ||
/(\/islands\/.+?\.tsx$)|(\/routes\/.*\_[a-zA-Z0-9[-]+\.island\.tsx$)|(\/routes.*\/\$[a-zA-Z0-9[-]+\.tsx$)/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it intended that there is no /
under routes
? If not, I think it should be added.
/(\/islands\/.+?\.tsx$)|(\/routes\/.*\_[a-zA-Z0-9[-]+\.island\.tsx$)|(\/routes.*\/\$[a-zA-Z0-9[-]+\.tsx$)/ | |
/(\/islands\/.+?\.tsx$)|(\/routes\/.*\_[a-zA-Z0-9[-]+\.island\.tsx$)|(\/routes\/.*\/\$[a-zA-Z0-9[-]+\.tsx$)/ |
We might also want to take this opportunity to review our existing regular expressions as well. I think I can summarize as follows
return id.match(
/\/islands\/.+?\.tsx$|\/routes\/(?:.*\/)?(?:\_[a-zA-Z0-9-]+\.island\.tsx$|\$[a-zA-Z0-9-]+\.tsx$)/
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it intended that there is no
/
underroutes
? If not, I think it should be added.
I'd like it to match /routes/$counter.tsx
.
Is
[
necessary?
Exactly, no! It's not necessary. It's (maybe my) fault.
return id.match(
/\/islands\/.+?\.tsx$|\/routes\/(?:.*\/)?(?:\_[a-zA-Z0-9-]+\.island\.tsx$|\$[a-zA-Z0-9-]+\.tsx$)/
)
Great! This will match /routes/$counter.tsx
. I'll change the regex to yours and add some tests. I'll add you as a co-author for this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Co-authored-by: Taku Amano <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! LGTM
Merging! |
With this PR, the component file whose name has
$
as a prefix, like/app/routes/dir/$counter.tsx
, will be treated as an island component.Before this PR, the filenames which are island components are below:
/islands
-/islands/conter.tsx
.island.tsx
suffix -/app/routes/dir/_counter.island.tsx
From my experience using HonoX, it's sometimes easy to handle if the island component is in the same directory with the route file. So the
2
is better. But I'd make it a simpler and shorter name.$
prefix -/app/routes/dir/$counter.tsx
Why
$
- this is just my taste, but I think it's easy to understand.I'll work on #159 after merging this PR.