-
Notifications
You must be signed in to change notification settings - Fork 111
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
Update to version 3.4 throw ex :[Right-hand side of 'instanceof' is not an object] #189
Comments
Thanks for the extensive write-up. Sadly the code you are referencing is not in the current release (neither the
While I understand that the referenced commit broke your use-case, we still need to have the shadowed elements code work. Since I still don't have a "this doesn't work" reproduction, I can't actually fix this error. |
I will try swapping those two lines and see if anything breaks, but I don't have any test coverage for use in any browsers besides Chrome and no tests for use in Node or package-managed uses... so it may break things elsewhere. |
There's a prerelease v.3.4.5-beta.0, please try it @codesculpture |
This is equivalent to Hence, the logic is changed anyway. |
If you can give a PR that adds a test so I can verify the bug and the fix, then I can address the situation. Otherwise, the best I can suggest is using an earlier version. The ShadowDOM fix is not getting backed out for something I cannot reproduce. Have you tested the 3.4.5-beta.0 release? |
Seems 3.4.5-beta.0 fixed the issue, this commit To reproduce this issue, And in const transform = async (dom) => {
const domtoimage = await import('dom-to-image-more');
await domtoimage.toSvg(dom, {});
}
function App() {
return (
<div>
<div id="hello"> </div>
<button onClick={() => {
transform(document.getElementById("hello"))
}}> Hello </button>
</div>
)
}
export default App Click ExpectedNo errors Actual
But if you switch to Then if you click Seems bundlers (i tested with rollup and webpack), bundles dynamic import by passing custom @IDisposable Am not sure is it possible to write test case for this scenario, wdyt |
Glad that it fixed it... we should just hope it broke nothing new... all my existing tests still work. Released as v3.4.5 (non-beta) |
If existing tests works, then i guess we are good. Will try to write test that it imports dom-to-image-more using Also thanks @IDisposable |
Duplicating this issue since it is closed, but it should be opened.
This is a interesting issue, since a single change did lot of things from this single commit
Object.hasOwn(value, 'getRootNode')
is replaced by'getRootNode' in value
But which is semantically not equal, as per mdn,
Object.hasOwn
The Object.hasOwn() static method returns true if the specified object has the indicated property as its own property. If the property is inherited, or does not exist, the method returns false.
in
operatorThe in operator tests if a string or symbol property is present in an object or its prototype chain. If you want to check for only non-inherited properties, use Object.hasOwn() instead.
That being said, if
obj
hasprop
andprop
is a inherited member,Object.has(obj, prop)
would returnfalse
, which is correctwhereas,
'prop' in obj
would returntrue
, which is also correct as per spec.So what happened here is that
getRootNode
is fromNode
But what we have as
value
isHTMLElement
which inherits
Node
,so
Object.hasOwn(value, 'getRootNode')
probably returns false, sincegetRootNode
is a inherited member fromNode
inHTMLElement
but
'getRootNode' in value
would happily returnstrue
, since that is correct.So the logic previously returned
false
but now the same logic returningtrue
, which changed the execution flow and would execute this block of codehttps://github.com/1904labs/dom-to-image-more/blob/e7d6ab0535a2477eb1a2b7226105fa1b7c6075a1/src/dom-to-image-more.js#L648C1-L655C10
where
global
would be a empty object, ifdom-to-image-more
was loaded through dynamic import usingwebpack
, wherewebpack
is importingdom-to-image-more
byeval(import("https://mycdn.com/dom-to-image-more.min.js"))
, here if a script is executed througheval
thethis
object would be a empty object{}
For example,
eval(this)
would returns{}
so
global
is{}
at this point, so we are doingvalue instanceof global.ShadowRoot
whereglobal
is{}
thus the rhs ofinstanceof
would be undefined. Throwing error.The error occured for me while using bundler such as
webpack
and dynamically importeddom-to-image-more
usingimport()
.I believe the fix would be
i.e the the existence of
window
would be checked beforeglobal
(just swapping two lines)@IDisposable
The text was updated successfully, but these errors were encountered: