GithubHelp home page GithubHelp logo

Comments (10)

apucacao avatar apucacao commented on June 3, 2024 3

Hi @maxholman, sorry for the delay here. This looks like a bug. I've added it to the list, and we should have a fix out shortly. I'll let you know once we've released a fix.

from js-client-sdk.

apucacao avatar apucacao commented on June 3, 2024

Hi @maxholman ,

Thanks for reaching out.

We only connect to the stream for updates if you subscribe to the change event. When updates from the stream arrive — and you bootstrapped using localStoragethe client will update that cache to ensure that on the next refresh localStorage contains the last known settings from the server.

Does that make sense?

Best,
Alexis

from js-client-sdk.

maxholman avatar maxholman commented on June 3, 2024

Thanks @apucacao - gotcha.

How can I get my app to react to these changes that are not streamed in, and are also not in localStorage at bootstrap time?

Calling getFlags on ready returns the in-memory state which can be stale (not the same as localStorage or the server state)

It seems like the purpose of the change event is to notify subscribers simply that flags have changed.

Should it not be emitted both when changes arrive through the stream (as you mentioned) but also when fetchFlagSettings updates localStorage? They are both "changes"

from js-client-sdk.

apucacao avatar apucacao commented on June 3, 2024

Ah, I see. Do you subscribe to change in your application? If you do, then you should get the latest settings from the server upon connecting to the stream. (We fetch once on connect.) Am I understanding correctly? Is that not working?

If you don't subscribe to change, then we have no way of letting you know that the latest settings we received were different from those you got from calling allFlags on ready. And to avoid discrepancies between calls to variation and the initial state you got on ready, we don't update the in-memory state.

from js-client-sdk.

maxholman avatar maxholman commented on June 3, 2024

My change subscription is working as expected for when something comes across the stream.

After some more digging, it looks like stream.connect callback isn't firing for me on connect, but only when some inbound event arrives.

I'll see if I can troubleshoot more from here, but essentially this means that the fetchFlagSettings and updateSettings doesn't get called when the stream connects and therefore no change event occurs, causing the issue as described.

from js-client-sdk.

maxholman avatar maxholman commented on June 3, 2024

Looks like there are no ping events occuring on the stream until I make a change on launchdarkly.com - so the onPing callback which is set via stream.connect() and updates the settings, doesnt fire when the stream connects.

from js-client-sdk.

apucacao avatar apucacao commented on June 3, 2024

Right that makes sense. I'm wondering how your original scenario can become a problem though: if the in-memory state — which you got from allFlags on ready — becomes stale, then since you're connected to the stream, that should rectify itself rather quickly?

from js-client-sdk.

maxholman avatar maxholman commented on June 3, 2024

This seems to be happening:

  1. Client is initialised
  2. flags is populated from localStorage
  3. fetchFlagSettings called to get latest response from server
  4. (async) localStorage is updated with latest response (no events are emitted and flags may be stale)
  5. I register a change event listener
  6. (async) Stream connects automatically due to event listener attach

At this point localStorage has the latest response, but flags is stale and reflects the state of localStorage on load.

I was expecting either:

a) Step 4 would emit a change event and update the in-memory flags, or
b) Step 6 should result in an initial ping event being received which then calls the stream.connect callback -> fetchFlagSettings -> updateSettings and finally emit('change')

Unfortunately neither of those happen so I am unable to get the absolute latest flags on load.

EDIT:

you should get the latest settings from the server upon connecting to the stream. (We fetch once on connect.)

I think this seems to be real issue, my client doesn't fetch on connect because it doesn't receive a ping.

from js-client-sdk.

apucacao avatar apucacao commented on June 3, 2024

Hi @maxholman — we should be sending the initial ping even again. Have you tried this recently?

from js-client-sdk.

maxholman avatar maxholman commented on June 3, 2024

Hi @apucacao - Just tried this again, still not seeing an initial ping and I still have the same issue I'm afraid

from js-client-sdk.

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.