-
Notifications
You must be signed in to change notification settings - Fork 149
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
Make React bundle work server-side #415
Make React bundle work server-side #415
Conversation
Thanks a lot for helping with this. One thing that worries me is this change:
As we discussed in the issue, we probably want a completely different component to be rendered server side. We want people to send the markup from the progressive enhancement section to users before loading the JavaScript, instead of sending a variation of the enhanced component. What're your thoughts on ensuring that we don't encourage folks rendering a broken experience server side? |
If you look at their example will give more context: |
Perhaps some guidance in the README explaining server rendering could help. |
Thanks for looking at this. Must apologize though, been meaning to look at this for aaaages after I raised the issue! Good timing though as I'm picking the work up again next week. For what it's worth I agree with the comment about "we probably want a completely different component to be rendered server side" so I think this fix should probably just be all the bits that break loading this component in a Node environment. |
Hi @NickColley and @ediblecode Thanks for your comments. With regards to wanting a different component rendered server-side, I have a couple of thoughts. My first thought is that it really depends on your use case for this component as to what you'd want rendered server-side for the case where JS is turned off or not loading for whatever reason. For example, in my personal use case, I want to use this component on my app merely as a way to suggest values to the user, so that they don't have to type the full value every time. In this case, just returning a default My second thought is that if you're rendering a As you both suggested, I think the server-side fallback could do with some more thought, possibly having multiple options to account for the use cases I outlined above. I've therefore removed the last commit around changing the server-side fallback, so that this can be addressed either directly by the person using the component in their app, or by us or anyone else in a future enhancement PR. At least this way, as @ediblecode says, this fix can just be the bits that break loading this component in a Node environment. |
@andymsuk thanks for updating that, it's looking good I think the only last things to do are:
I can do this on your behalf if you want, let me know. |
4960bbc
to
f4a8976
Compare
Thanks @NickColley. I've tidied up the commits and added to the CHANGELOG, but feel free to edit/tidy more if you'd like. |
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 makes sense to me, thanks for the tidy, CHANGELOG looks great too.
@ediblecode would you mind giving this a review too please?
Looks good to me, have approved. Thanks @NickColley and @andymsuk |
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.
Looks good to me 👍It'd be good to update the PR description to strike-through the changes that are no longer included – I was originally looking for those changes in the files changed and it took me a few minutes to read through the conversation and work out what was going on.
Overview
Fixes #352, so that the component can be used in a server-side React environment.
Changes
globalObject
to'this'
in the React Webpack config, so that it doesn't have unwanted references towindow
, in order for it to work in a server-side environmentnavigator
is defined before using it, in order for it to work in a server-side environmentOnly include therole
ofcombobox
once the component has mounted, so that the server-side rendered markup (i.e. when the user has JavaScript turned off) has norole
attribute, and so it's role defaults back totextbox
Only include the aria hint (aria-describedby
) once the component has mounted, so that the server-side rendered markup (i.e. when the user has JavaScript turned off) has noaria-describedby
as it doesn't make sense if there the JavaScript is not running.