-
Notifications
You must be signed in to change notification settings - Fork 323
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
Foundational work to split hydrogen-ui to its own package #1060
Conversation
We detected some changes in |
|
||
function App({routes}) { | ||
return ( | ||
<Suspense fallback={<LoadingFallback />}> | ||
<ShopifyProvider shopifyConfig={shopifyConfig}> | ||
<CartProvider> | ||
<DefaultSeo /> | ||
<TestServer /> | ||
<TestClient /> | ||
{COOLNUMBER} |
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'll remove this before merging, this is just if anyone wants to pull it down and test it locally
path.join( | ||
// eslint-disable-next-line node/no-missing-require | ||
path.dirname(require.resolve('@shopify/hydrogen-ui/client')) | ||
), |
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.
@frandiox @jplhomer This causes the CI build failures (because the e2e test package hasn't installed hydrogen-ui. But this will also be true of devs already building on hydrogen, too).
So I think we have a couple of options here:
- We leave this as is, but that means we also require that everyone install the
hydrogen-ui
. This probably isn't ideal, as it would mean that as soon as this PR is merged then it's a breaking change (and we don't have hydrogen-ui publishing to npm yet either, so devs can't even install the stub) - We modify the Vite plugin to take in additional "componentPaths" and we spread them here. Which means for the demo store we can add hydrogen-ui
- We wait on Improve component discoverability in client build #994
Thoughts? Other options?
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 fails because resolve.require
cannot find the package, right? In that case, can we just wrap it in try/catch and only pass it if the package is actually found? 🤔
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.
Yeah, I actually tried doing that last week and for some reason it wasn't working. I'll try it again and give some better details as to why
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.
Worked this time. I must have been doing something weird last week 🤷 👍
@@ -6,13 +6,21 @@ import DefaultSeo from './components/DefaultSeo.server'; | |||
import NotFound from './components/NotFound.server'; | |||
import LoadingFallback from './components/LoadingFallback'; | |||
import CartProvider from './components/CartProvider.client'; | |||
import {Test as TestServer} from '@shopify/hydrogen-ui/server'; | |||
import { | |||
// Test as TestClient, |
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.
@frandiox @jplhomer It maybe appears that tree-shaking isn't working here; when I run a build for the template-hydrogen-default
package, I can do a search in the dist/
folder for the contents of TestClient (which is the word mycoolcomponentclient
) and find instances of that in every build, both server and client.
As far as I can tell, I've implemented the necessary "magic" which should allow hydrogen-ui
components to be tree-shaken. I could be wrong, but I think things are correct there.
So, the problem is either:
hydrogen-ui
isn't configured correctly for tree-shaking- The
template-hydrogen-default
build script isn't correctly tree-shaking - Our Vite plugin doesn't properly allow tree-shaking to happen
- Something else?
What do you think?
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.
This is something I've seen in Vite before. Everything in index.ts
is not tree-shaken for some reason. It needs further research but I'm hoping we can indicate some kind of "moduleSideEffect: false" for every component and let the tree-shake work. Otherwise we'll need to import from different paths 🙈
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.
It's strange that Vite doesn't pick up on sideEffects: false
in package.json
for this, since I believe that it normally does
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.
Opened #1071 to continue this discussion
} | ||
}, | ||
"typesVersions": { | ||
"<=4.6": { |
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.
Package exports supported in 4.7 https://devblogs.microsoft.com/typescript/announcing-typescript-4-7-beta/#package-json-exports-imports-and-self-referencing
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.
If package.exports becomes a problem with TS or Jest, we can also simply rely on real files at the root like we do in hydrogen
(client.js
and server.js
next to dist
directory).
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.
They shouldn't be, I've gotten TS (all versions) and Jest all figured out with package exports! 👍 Check out the CONTRIBUTING.md
file for details.
2976ae8
to
13376ef
Compare
@@ -0,0 +1,11 @@ | |||
## Package exports notes: | |||
|
|||
- Until [Jest can correctly resolve package.exports](https://github.com/facebook/jest/issues/9771), here's a workaround: |
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.
Curious if you know, would vitest would also require a workaround?
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.
Not sure right off hand, but I can look into 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.
Though I am planning on converting tests over to Vitest for our own internal components tests.
* v1.x-2022-07: (37 commits) Adds Shopify/hydrogen-cli for development server (#1089) Make `useUrl()` reactive for subscribing to navigation events (#1082) fix e2e tests streaming and suspense draft (#1033) [Hydrogen docs]: Restructure and simplify IA (#1079) Use new storefront API headers in queryShop API helper (#1075) Remove the dep of hydrogen-ui for now until we get it publishing (#1076) [ci] release v1.x-2022-07 (#1048) Introduce a synchronous-looking version of fetch for server and client (#983) improve the current type of ShopifyContextValue to be based on ShopifyConfig (#1072) Foundational work to split hydrogen-ui to its own package (#1060) Allow returning new requests from API routes (#1057) [Hydrogen docs]: Analytics (#962) Analytics (#890) Allow line breaks inside script tags (#1061) Fix encoding of CSS Modules to solve hydration errors (#1062) [Hydrogen docs]: Update guidance on troubleshooting third-party dependencies (#1055) Update Vite RSC Plugin (#1054) Fix link prefetch (#1059) Initial devTools component (#998) ...
Description
Part of #66, and depends on #1054 being merged.
The package split! A better version of #628, this time with:
Quick followup work that's planned:
Shopify/hydrogen#66 (comment)
Additional context
Before submitting the PR, please make sure you do the following:
fixes #123
)yarn changeset add
if this PR cause a version bump based on Keep a Changelog and adheres to Semantic Versioning