-
Notifications
You must be signed in to change notification settings - Fork 295
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
Certain Vite HMR updates break when the components index.ts file passes a certain threshold of exports #2768
Comments
At first, I thought it might be the index barrel exports you have with the components folder .. but I couldn't reproduce the I'll need a more simple, reproducible project that cause the multiple files listed in that The fact that |
@wizardlyhel If you then comment in all the
I would figure there would be nothing wrong with the project setup as this was fine with the Classic Remix Compiler, and is also fine in a non-Hydrogen Remix-Vite application, where I'll create a simpler project that outlines an hmr update that lists all files, even if it doesn't error out. I'll work off the demo store. |
As reference, with the Hydrogen demo store as is, if you go into |
Okay I was right about the index barrel file. If you change how you import your component file, it would fix this issue. // app/routes/($locale).products.$handle.tsx
- import {Product} from '~/components/;
+ import {Product} from '~/components/Product'; I'm guessing you have hit some hmr limit. I'm not sure where's the limit is that is causing the error. |
@wizardlyhel So the Hydrogen + Vite solution is to no longer have all our components exported from just the |
It might be within Hydrogen as we are using workerd (to simulate a Cloudflare worker like local environment). We can look deeper into this but it won't be fast turn around to fix this issue |
@wizardlyhel Got it! To the small handful of stores we migrated to Vite, we will migrate back to the Classic Remix Compiler to avoid our devs from experiencing new limiting caveats and dev errors. Migrating to Vite doesn't seem to be a "requirement" for Hydrogen any time soon, rather a nice to have, if I'm understanding its support in Hydrogen correctly. If/when there is further discovery on this and a release, we will migrate to Vite. Thank you! |
Ok now I'm contemplating removing the use of barrel files 🤔 |
What is the location of your example repository?
https://github.com/jeremyagabriel/hydrogen-demo-store
Which package or tool is having this issue?
Hydrogen
What version of that package or tool are you using?
2025.1.1
What version of Remix are you using?
2.15.3
Steps to Reproduce
npm install
, then run locally vianpm run dev
. Ensure the terminal and browser console are visiblemetafields
console log with a single entry in the objectapp/lib/constants/product.ts
file, comment in the second item in thePRODUCT_METAFIELDS_IDENTIFIERS
array[vite] hmr update
and following[Error: internal error]
in the terminal. If there is NO error at this step, see * belowmetafields
console log logs with only one entry in the object, implying the file change did not register. If the update DID register see *** belowmetafields
console log is finally updated, implying the change only occurs after a localhost restartapp/components/index.ts
file, comment out the last active Product export, e.g.export {Product5} from './Product5';
or whatever export was below the threshold needed to break HMR with the * footnote belowPRODUCT_METAFIELDS_IDENTIFIERS
array inapp/lib/constants/product.ts
and save[Error: internal error]
in the terminal, and themetafields
console log will reflect the additional entry either upon save OR after page refresh*If for some reason there is no
[Error: internal error]
at this step, kill localhost, then comment in an additional Product component export in theapp/components/index.ts
file and comment back out the line from step 3. Restart localhost and repeat step 3. If again there is no[Error: internal error]
add another Product export, repeat the steps in this footnote.***Sometimes a
[Error: internal error]
will still apply the intended changes, thus you will see the intended metafields update. You can comment out that line again in thePRODUCT_METAFIELDS_IDENTIFIERS
array, save, restart localhost, and repeat step 3. If the intended change still applies with[Error: internal error]
, you can technically move on, as the error still occurred and is the crux of the issue.NOTE:
[Error: internal error]
may sometimes only log alongside the first erroneous[vite] hmr update
with a fresh localhost, where subsequent[vite] hmr update
in the same localhost session may not have the error logged, but will likely still have a broken HMR. Restart localhost if you want to ensure[Error: internal error]
in the erroneous logExpected Behavior
In a non-Hydrogen Remix Vite app, where there is no
virutal:
server, this particular save (from the reproduction steps) would simply result in[vite] page reload
in the terminal where HMR doesn't apply but the changes are still registered after a page reload. As I understand it, thevirtual:
server with the Hydrogen template doesn't apply a[vite] page reload
for this kind of save, but instead applies[vite] hmr update
, but with a list of the codebase's files, but the changes still apply nonetheless. I'm unclear why the list of files is part of the hmr update log, but assuming it's part of the workaround in lieu of[vite] page reload
with thevirtual:
server?Actual Behavior
Once the
index.ts
file for/components
reaches a certain threshold of exports, the[vite] hmr update
for these kinds of saves will be followed by[Error: internal error]
where the change in the file does not apply and you must restart localhost. Note, the supposed threshold isn't the number of exports, rather the culmination of the number of files between all the exports.Note: with this test repo, certain circumstances even with the
[Error: internal error]
, intended changes can still be observed. In practice with our online stores, the changes are not observed and we must constantly restart localhost after every one of these kinds of saves, which can make the dev experience unusable.The text was updated successfully, but these errors were encountered: