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
Selected ListItem styles not working with SSR #492
Comments
@dan-kwiat yes from my understanding of how SSR works, I believe the problem is with MDC React and not Web. I'm not super familiar with SSR. Do you have a test project that I can look at/learn from with the List HTML shown above? |
@moog16 to be honest I'm pretty new to SSR as well. This example has a List in the Drawer (see DrawerList.js): https://github.com/dan-kwiat/material-next-template In development the first item is selected as expected (see screenshot below) and it responds to item clicks. In next's static build however no item is selected (see demo) and |
I visited your demo https://dan-kwiat.github.io/material-next-template/ and downloaded your project. I noticed that the In your dev setup, clicking on a list item console.log(), but this does not happen in your live demo. |
@moog16 it isn't being called because |
@dan-kwiat I looked into this more this afternoon. I think it may have something to do with componentDidMount which is not being called when the site is server rendered. Would you be able to test this? I haven't had time. |
@moog16 I think the problem is the use of Therefore with SSR Thanks for your time on this. |
@moog16 so this is a code minification problem, nothing to do with SSR. Same problem with a create-react-app build. A workaround would be to define the list item type at the top of index.js as: const ListItemType = (<ListItem/>).type then replace the condition in if (child.type.name === 'ListItem') {...} // current condition fails with code minification
if (child.type === ListItemType) {...} // this should work More on element type comparisons here: gaearon/react-hot-loader#304 Edit: comparing to "rendered" element type isn't necessary unless using react-hot-loader |
@dan-kwiat thanks for figuring that out! I spent quite a bit of time and couldn't figure it out. I'll try testing this out with your SSR demo. |
Merged #509...thanks again! |
With client-side rendering the first item gets the
mdc-list-item--selected
class andaria-selected="true"
as expected. However with server-side rendering (tested with next.js) this is not the case (and all the items look the same). I believe it's an issue with this library rather than material-components-web?The text was updated successfully, but these errors were encountered: