-
Notifications
You must be signed in to change notification settings - Fork 324
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
Define how devs import components and functions #1154
Comments
@frehner I'm not sure if this is still a valid approach that we can take, but I really liked @jplhomer's suggestion about just telling developers to import everything from If we can take away the decision-making of having developers choose between Having For whatever direction we choose to take, I think there's an opportunity here as well to improve our error messaging when it comes to importing functionality in Hydrogen. Surfacing constraints and limitations, and providing avenues to solve problems (potentially by linking to a "troubleshooting" section in the docs), in-context of building on Hydrogen, will be critical to developer success. |
Re the desired developer experience, I agree with the approach of always trying to follow the same import pattern: import { thing } from '@shopify/hydrogen' I recently had cause to use Keystone and I found its approach to imports challenging, precisely because it splits them up as separate concerns, so you end up with a situation like: import { config } from '@keystone-6/core'
import { a, b, c } from '@keystone-6/fields'
import { x, y z } from '@keystone-6/fields-document'
import { imageStuff } from '@keystone-6/cloudinary' So now instead of one discovery layer — what There's surely some overhead in making this approach a reality, but I think it's preferable to move the necessary complexity into Hydrogen, instead of externalizing it to the user. While we're on the subject, would love to think about how we make that first discovery layer ( |
Would it be correct to say it sounds like both of you are less concerned about whether an import works or not (e.g. "if I import a server component in a client component it breaks, so help me prevent that") and that we should focus more on just importing everything from a single place to lessen the cognitive load on figuring out where to import from? |
I'd agree with that. In practice, import discovery can be quite ambiguous and dispersed, and leans heavily on documentation and tutorial content, so whatever we can do to reduce complexity up front is worthwhile. In contrast, component breakage is obvious and immediate — you'll see it right away in your browser, dev tools, and terminal, and we can build error patterns across all those surfaces that make debugging, diagnosis, and recovery easier. |
I'd agree as well, and +1 to Graham's thoughts! |
One additional consideration: Currently, RSC relies on the fact that client components end in If we have to follow that convention, then having a single import path like import {ClientComp, ServerComp} from '@shopify/hydrogen' either doesn’t work or requires additional tooling in order to get working correctly. So for the time being it may not even be feasible to have a “single” import path, or may not be possible for GA. |
Related to #896 and recent discussions, we need to clearly define
In our initial discussions on solving this, we ran into problems: for one example, if we import from
@shopify/hydrogen/client
, does that mean that:Additional questions/context:
/client
, but that function will not work when imported in a server function. So would we need to create a separate export for components vs hooks/JS functions?/client
means "only works in the client env", then RSC client components cannot be exposed from/client
because you can import an RSC client component in the serverhydrogen
and/orhydrogen-ui
?Tagging @blittle
The text was updated successfully, but these errors were encountered: