-
Notifications
You must be signed in to change notification settings - Fork 71
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
Event proxy causes undefined method push errors when calling native object methods #162
Comments
Thank you for reporting this. We are investigating the issue. This has been filed internally as 178466. |
@yusinto Can you clarify: if someone upgrades to 2.27.0 and sets |
@hwangm the @subvertallchris you won't lose the behavior in 2.26.0 by setting Please refer to the docs for more information. @hwangm I will investigate the error on invoking native object methods on the flags object. |
We reproduced the issue and have found the cause and the corresponding fix. A new release will be published soon with the fix. Thank you all for your patience. |
This has been fixed in v2.29.3. |
@yusinto thank you very much for the prompt updates and fix! much appreciated. |
Describe the bug
If LD is configured to send events on flag read, when application code calls native object methods such as
hasOwnProperty
on theflags
data from theuseFlags
hook, an error gets thrown and subsequent events do not get sent to LD.To reproduce
sendEventsOnFlagRead
option (or set totrue
) usingreact-client-sdk@2.27.0
useFlags
hook API to get a list of feature flagsflags
object e.g.hasOwnProperty('name')
orpropertyIsEnumerable('name')
Expected behavior
If native object methods are called on the
flags
object, they should be excluded from the flag read event map and no error should be thrown.Logs
The undefined error occurs when the events are flushed to LD via the EventSummarizer (https://github.com/launchdarkly/js-sdk-common/blob/main/src/EventSummarizer.js#L63). I installed local copies of the
js-client-sdk
andjs-sdk-common
packages to add debugging around these files to see what the flag contents were (ss below):I was able to identify application code that used conditionals checking against the flag name to perform some behavior:
where
useFeatureFlags
is defined as:To test whether this was the issue, I first deleted any references to
hasOwnProperty
on theflags
object, saw that the error was gone, then added new lines callingallFlags.propertyIsEnumerable('name')
to check if the error returned, resulting in the SS above. I also verified that setting the config optionsendEventsOnFlagRead=false
eliminates the error even if native Object methods are called.It appears that the JS proxy introduced in 2.27.0 considers native Object methods as flag keys and will add them to the flag map for count tracking unless the config option
sendEventsOnFlagRead
is explicitly set tofalse
.SDK version
react-client-sdk@2.27.0
and higher. I verified that this bug is present in all released versions after 2.27.0.Language version, developer tools
Node 16.18, TS 4.7.3, React 17.0.2
OS/platform
Mac OS 12.6, M1 chip
Additional context
This should be considered a breaking change if applications have code that calls native Object methods on the
flags
object and do not explicitly set this new configuration tofalse
, as errors will immediately start happening after upgrade and events will stop being set to LD.Can someone from the LD team clarify whether this feature of sending events on flag read was something that was being done by default before this change, or is a new feature as a result of introducing the JS Proxy?
The text was updated successfully, but these errors were encountered: