-
Notifications
You must be signed in to change notification settings - Fork 35
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
Feature: Allow loading flags in React SSR #2
Comments
Resolved |
1 similar comment
Resolved |
When using the client with react, I would expect to be able to render from the server (initial render - we use Next.js and this is what happens). |
This has been split into 2 issues. Firstly, the client shouldn’t break when being imported on the server. This can be tracked here #9. This has been resolved as of 0.70, there's a nextjs example in this repository. This issue will be for adding the ability to retrieve flags on the server. The difficulty here is the bulletTrain init function has a success callback. One option would be to have the init function return a promise with the initial flags. However, the problem is a bit more complex than that as with SSR you may want to include an identity in your initial fetch to flags. For this to work on next you’d need to use a cookie implementation that can be accessed from both the client and server. Rather than bloat the client I’ll add an example react next app on how to do this. |
This has now been implemented in the latest 0.7x.x version of the client, an example of SSR with nextjs can be found here. It was a bit trickier than I thought, in order to make this possible, the client needed a way to restore state on the client. The readme in the above example should explain everything. Any questions, feel free to reopen. |
To people stumbling across this, as of 0.80.0, you will need to do.
This has been reflected in the nextjs example in this repository. |
Is there anyway I can use the JS client in React App that uses Server Side Rendering?
Right now, the seems the client requires a
window
object to work. Which prevent it from being used in an app that uses SSR (our apps uses Next.js).The text was updated successfully, but these errors were encountered: