Comments (10)
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.
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 localStorage
— the 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.
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.
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.
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.
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.
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.
This seems to be happening:
- Client is initialised
flags
is populated fromlocalStorage
fetchFlagSettings
called to get latest response from server- (async)
localStorage
is updated with latest response (no events are emitted andflags
may be stale) - I register a
change
event listener - (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.
Hi @maxholman — we should be sending the initial ping
even again. Have you tried this recently?
from js-client-sdk.
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)
- Lighthouse audit fails with `no-unload-listeners` HOT 5
- Support running in browser extension service workers HOT 19
- Consider providing ES6 builds HOT 5
- Ublock Origin blocks some LaunchDarkly URLs HOT 6
- Event streaming in iOS standalone browser HOT 12
- Experimentation docs reference a version that is unreleased HOT 1
- client already exist error HOT 2
- Safari v12 and v13 error for package versions 3.0.0 and above HOT 3
- SDKs >= 3.0.0 no longer send click or pageview events HOT 1
- Pull only a sub set of flags for a project HOT 1
- Support passing context to the `variation` call? HOT 1
- Add opentelemetry tracing to server calls HOT 2
- Warning logged about omitting identify when client is bootstrapped HOT 4
- Unhandled Exception occurs when there is a network error HOT 5
- LD double initialisation with Strict Mode set to true.
- Bypass "do not track" setting in development environment HOT 1
- How do we retrieve the tags or custom properties using ldclient? HOT 2
- Allow to evaluate specific flags HOT 2
- option to disable logger in browser console HOT 1
- Access to XMLHttpRequest at 'https://events.launchdarkly.com/events/bulk/6374af9a71e138110cdb10cd' from origin 'https://localhost:5001' has been blocked by CORS policy: Request header field request-context is not allowed by Access-Control-Allow-Headers in preflight response. HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from js-client-sdk.