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

Infinite loop when adding DOM element #507

Closed
krom-xr opened this issue Jul 25, 2018 · 3 comments
Closed

Infinite loop when adding DOM element #507

krom-xr opened this issue Jul 25, 2018 · 3 comments

Comments

@krom-xr
Copy link

krom-xr commented Jul 25, 2018

let example = new Baobab({test: {}})
let divEl = document.createElement('div');
example.select('test').set({div: divEl});

After .set(...) - infinite loop. Browser tab not responding

@Yomguithereal
Copy link
Owner

Hello @krom-xr. Normally, a Baobab tree is not supposed to hold anything but raw data, not DOM elements. However this case seems quite strange indeed. I think the tree tries to deep clone the element and stumble upon cyclic references and such. If you really want to do that, you can try turning off the persistent option of your tree. I guess this should fix this use case:

let example = new Baobab({test: {}}, {persistent: false});

@krom-xr
Copy link
Author

krom-xr commented Jul 25, 2018

Ok. Thanks.
But may be best solution - throw error in that case. If it possible?

In may case -
I put stream (webrtc stream) to Baobab store.
In one option i put canvas.captureStream() (empty stream).
There was ok in chrome - but infinite loop in firefox.
Because stream instance - have link to canvas in firefox.

    CanvasCaptureMediaStream {
​​        active: true
        canvas: <canvas id="webrtc-empty-video" hidden="">
        currentTime: 5.358
​        id: "{dfb95857-2aa8-b14e-a239-bb14cdda3ef6}"
        onaddtrack: null
        onremovetrack: null 
       ...
    }

Thanks for answering. Now i solve my problem. But may be other users can fall into similar situation

@Yomguithereal
Copy link
Owner

But may be best solution - throw error in that case. If it possible?

Probably so. But checking for circular reference does have a performance cost.

You should really avoid storing classes from the DOM in a Baobab tree if you can, though.

@krom-xr krom-xr closed this as completed Aug 13, 2018
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