Skip to content
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

events.slice is not a function #96

Closed
dvargas92495 opened this issue Oct 10, 2023 · 4 comments
Closed

events.slice is not a function #96

dvargas92495 opened this issue Oct 10, 2023 · 4 comments

Comments

@dvargas92495
Copy link

Describe the bug
Intermittently, I'm seeing this line throw a type error bc events is not an array, both in the browser and during jest testing.

To reproduce
I could try to post a minimal reproducible repo if it would help, but I think I see what's going wrong in the code itself:

  • chunkEventsForUrl is expecting events to be an array
  • it's called by EventSender.sendEvents here which is also expecting events to be an array.
  • However, that's called by sendDiagnosticEvent here, which is passing in only a single event to the whole flow, which then triggers the events.slice is not a function error. I believe the argument here should be [event] - it's not clear to me what's sending the diagnostic event based on the traceback.

My use case is a bit involved so it would take time to narrow down to a minimal reproducible example, especially since the error triggers non-deterministically. However, I believe the code fix here appears to be straightforward enough without one.

Expected behavior
Launch Darkly sdk to run without erroring

Logs
Screenshot 2023-10-10 at 11 57 55 AM

SDK version
└─┬ launchdarkly-react-client-sdk@3.0.4
└─┬ launchdarkly-js-client-sdk@3.1.2
└── launchdarkly-js-sdk-common@5.0.3

Language version, developer tools
npm -v
8.19.3
node -v
v16.19.0

OS/platform
Mac M1 Apple Silicon

Additional context
N/A

@kinyoklion
Copy link
Member

Hello @dvargas92495,

I agree that this is a bug, but generally speaking should not be happening (or at least not often) for real users. We will be releasing some new SDKs soon that do not contain this functionality.

The reason it generally should not be happening is that we should not be chunking events for platforms that support post. Being as browsers for some time have effectively universally supported post, this likely was missed during testing, with diagnostic events being added at a point where the lack of post support was uncommon.

I am concerned though that possibly POST support detection is not working correctly in some situation. Do you have any meta-data for browsers that have been encountering this error?

Thank you,
Ryan

@kinyoklion kinyoklion added the waiting for feedback Indicates LaunchDarkly is waiting for customer feedback before issue is closed due to staleness. label Oct 10, 2023
@dvargas92495
Copy link
Author

is that we should not be chunking events for platforms that support post.

By this do you mean HTTP POST requests, window.postMessage API, or some other third concept?

We are mainly hitting this during our jest unit testing, where we mock HTTP requests instead of the useFlags() hook. If you could point me in the direction of what it's checking for "supporting post" then we could likely improve our test dom environment to cover that and resolve this issue. Otherwise, we'll likely fallback to mocking useFlags() hook

@kinyoklion
Copy link
Member

@dvargas92495 HTTP POST support. The detection code for the js-client-sdk is here: https://github.com/launchdarkly/js-client-sdk/blob/8675ab6b0d1a4833e4e140af3658011bf48b2162/src/browserPlatform.js#L24

Technically it is support for CORS, but effectively we wouldn't be able to use HTTP POST from a browser without CORS support. When CORS isn't supported a workaround using HTTP GET is done.

@dvargas92495
Copy link
Author

ah ok I think that gives me what I need - thank you!

@kinyoklion kinyoklion removed the waiting for feedback Indicates LaunchDarkly is waiting for customer feedback before issue is closed due to staleness. label Oct 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants