Open jeffspurlock opened 2 months ago
So interestingly, if instead of passing collectionsMenu into the header component, if i just instantiate a new data=useLoaderData() inside the component, and access that it works. When its passed as a prop, it stays undefined until second render.
Hey @jeffspurlock,
Thanks for the report! Sounds super strange 🤔 I'm unable to replicate, any chance you could provide a demo repo?
What is the location of your example repository?
local
Which package or tool is having this issue?
Hydrogen
What version of that package or tool are you using?
2024.7.2
What version of Remix are you using?
2.10.1
Steps to Reproduce
If you modify the default HEADER_QUERY to include a request for two menus with aliases, like so
by default, this populates a header object in the loadCriticalData function. In the component of root.tsx, `const data = useRouteLoaderData<RootLoader<('root')' is called, and data is passed into the PageLayout component. In PageLayout, data is destructured in the props
inside of which, header is passed into the component. Note: so far the only thing that has changed from the default scaffolded hydrogen application is adding the second menu and aliases
Now inside, i'm destructuring the header object in the props as
if i
console.log(collectionsMenu)
, i can see all the data just fine, it has the shape ofbut then if i
console.log(collectionsMenu.items)
it will say its undefined. You can even log them one right after another; collectionsMenu logs correctly with an items property, but collectionsMenu.items or collectionsMenu['items'] logs undefined.Expected Behavior
I expect to be able to access the properties of the object returned by an asyncronous loader function that is set to await the result before returning it.
Actual Behavior
I cannot useLoaderData to build out my menu structures defined in shopify to populate the menu component on the site.