smartlook / smartlook-client

Official Smartlook client for easy frontend integration.
https://smartlook.com
MIT License
28 stars 9 forks source link

TypeError: Converting circular structure to JSON #21

Closed FerBarreraFraga closed 2 years ago

FerBarreraFraga commented 2 years ago

The following error occurs after interacting with an input when I initialized Smartlook

This is how I initialize Smartlook:

import sl from 'smartlook-client';

const useSmartlook = (): void => {
  useEffect(() => {
    if (!sl.initialized()) {
      initialize();
    }
  }, []);
};

image

Joozty commented 2 years ago

@Skope10 thanks for your report. Is your website publicly available so I could take I look or even better could you please provide us with a minimal reproducible example by any chance?

bscaspar commented 2 years ago

@Joozty here is a CSB link: https://codesandbox.io/s/mutable-rgb-xoorph?file=/src/App.tsx

To reproduce, select the input on the screen then wait ~5 seconds.

Changing the hidden input field id prop to anything but id prevents the error from happening. As does removing the useSmartlook hook.

Joozty commented 2 years ago

@bscaspar Thanks a lot. It is really appreciated. I identified the problem and prepared a fix which will get released tomorrow at some point.

To describe the issue we record IDs of elements so they can be used in events filtering and many other places in our app. When you have a structure like this and you try to access the form's id via document.querySelector('#test').id the result is not a string as one would expect but the input element itself which is not serializable in react's apps. We were aware of this behaviour but unfortunately did not cover it at all places. Obviously the most straightforward solution is using getAttribute method.

<form id="test">
    <input id="id">
</form>

Thanks again for your report and MRE. I will update you once it is released.

bscaspar commented 2 years ago

Sounds good thank you for the quick response!

Joozty commented 2 years ago

@bscaspar fix is released. I am closing this one. If there is any problem feel free to reopen.

bscaspar commented 2 years ago

@Joozty should we look for a patch version of the package?

Joozty commented 2 years ago

No need it should work without doing any changes in your codebase. This package is just a wrapper around our web-sdk script which is downloaded once you call initialize method.