Coder Social home page Coder Social logo

Comments (6)

kyle-ssg avatar kyle-ssg commented on June 22, 2024 1

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.

from flagsmith-js-client.

ukabu avatar ukabu commented on June 22, 2024

Resolved

from flagsmith-js-client.

kyle-ssg avatar kyle-ssg commented on June 22, 2024

Resolved

from flagsmith-js-client.

ukabu avatar ukabu commented on June 22, 2024

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).
Ideally, SSR would load the feature flags just like when using the nodejs client. But just being no-op on the server-side (when there is no ; window` global) would be enough. As long just requiring/importing the client does not throw an exception, it would be good.

from flagsmith-js-client.

kyle-ssg avatar kyle-ssg commented on June 22, 2024

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.
https://github.com/SolidStateGroup/bullet-train-js-client/tree/master/examples/nextjs

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.

from flagsmith-js-client.

kyle-ssg avatar kyle-ssg commented on June 22, 2024

To people stumbling across this, as of 0.80.0, you will need to do.

import bulletTrain from 'bullet-train-client/isomorphic';

This has been reflected in the nextjs example in this repository.

from flagsmith-js-client.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.