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

Can't clone objects created within iframes. #30

Open
juliofarah opened this issue Jun 9, 2021 · 3 comments
Open

Can't clone objects created within iframes. #30

juliofarah opened this issue Jun 9, 2021 · 3 comments

Comments

@juliofarah
Copy link

While testing a tool that uses klona/lite, I realized the library did not clone objects created within iframes.

There's a bigger discussion here about how prototypes are different for similar objects when created in different iframes (or within an iframe versus the top page).

When I create an object within an iframe:
image

this snippet https://github.com/lukeed/klona/blob/master/src/lite.js#L7-L13 is executed, given typeof x.constructor === 'function' and not object when the object is created within an iframe.

Line 10 though checks if the property already exists on the temporary object, which is empty, ignoring the property I'm trying to clone.

I got around the problem by switching from klona/lite to klona/full as the latter doesn't include that constructor check, but I'd love to switch back to shave those extra few bites off of my final bundle

@bodograumann
Copy link

Shouldn’t https://github.com/lukeed/klona/blob/master/src/index.js#L10 and https://github.com/lukeed/klona/blob/master/src/lite.js#L10 always check whether x.hasOwnProperty(k) instead of tmp.hasOwnProperty(k)?
Currently cloning class objects always gives empty objects iinm!

@tripodsgames
Copy link
Contributor

tripodsgames commented Sep 15, 2021

Shouldn’t https://github.com/lukeed/klona/blob/master/src/index.js#L10 and https://github.com/lukeed/klona/blob/master/src/lite.js#L10 always check whether x.hasOwnProperty(k) instead of tmp.hasOwnProperty(k)?
Currently cloning class objects always gives empty objects iinm!

Having this issue here too. Im using klona/full as a temporary fix.
@lukeed hasOwnProperty is really necessary?

@lukeed
Copy link
Owner

lukeed commented Oct 27, 2021

I believe this is now solved by #31 (thanks @tripodsgames) which includes @bodograumann's suggestion. If someone can verify that this is solved in the latest release (soon to be 2.0.5) that'd be much appreciated 🙇

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

4 participants