-
Notifications
You must be signed in to change notification settings - Fork 3
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
Add commonjs build #49
Conversation
Can you elaborate a bit more about this mismatch? Is this something all uses of the node version would encounter? Would it be noticeable to them? |
Server-side rendering works by creating an initial rendered HTML page and sending it to the client. The client will render that static page, and then the UI will become interactive once React starts running on the page (hydration). The server can't run run We could use https://www.npmjs.com/package/react-layout-effect so that Taking a step back, how useful would SSR be for an answers experience? The server can render pages at build time like a SSG, however that doesn't make much sense for answers since the content is dynamic and based on the user's query. I could see it being useful on experiences with a default initial search though. Servers can also render initial pages per request. For example, if someone loads a page with certain query params, NextJS could be configured to fetch the data necessary to render that page so that data will be included in the initial HTML it sends to the client. We'd need to talk to product to see if this is a use case that they'd want the library to handle out of the box. Getting full support for that would require us write our components in such a way that they can fetch data and render it without using The most likely use case that I imagine for using headless with SSR is when it's being plugged into a site which is already heavily leveraging SSR. In that case we'd want to update the lib to avoid the warning, however the answers portion of the experience wouldn't show any data until React starts on the client. |
This is what react-redux does for react on the server side, not saying we should do this just adding more context |
@cea2aj, would the isomorphic |
No, those functions would just fix the warning in the console, but they wouldn't improve the capabilities of the initial render. We'd have to test out the components with SSR to see if the components look broken. At worst, we'll have to disable SSR of the components and let client side React render the components |
We will hold off on merging this until product decides they want this functionality (Therefore marking as WIP) |
Add a commonjs build so that the library is compatible with node
There is a warning about useLayoutEffect since that is not compatible with server-side-rendering, however it still works. It will lead to a mismatch between the initial non-hydrated UI and the intended UI. If we do want to fully support that use case, there is more info here: https://gist.github.com/gaearon/e7d97cdf38a2907924ea12e4ebdf3c85, however that is out of scope of this item
J=SLAP-1666
TEST=manual
Use create-next-app and add answers-headless-react to it and test that a simple universal search works.