Skip to content

vanX: "TypeError: Illegal invocation" when using JS-native File object instead of custom one #156

Description

@metaleap

Hiya, I had a well-functioning vanx.Reactive<UpFile> (where type UpFile={name:string,type:string}) already fully working with vanx.list() and vanx.replace().

I had to directly swap out that little custom type with the browser/EcmaScript-native File (that's in urFileInput.files[]File also having those same 2 fields, and then some), and, with no other changes having been made to the code, now during replace() vanX throws like so:

van-1.2.3.js:17 TypeError: Illegal invocation
    at get (<anonymous>)
    at Object.get (van-x.js:29:11)
    at posts.js:76:65
    at van-x.js:57:13
    at runAndCaptureDeps (van-1.2.3.js:15:12)
    at bind (van-1.2.3.js:74:16)
    at add (van-1.2.3.js:94:32)
    at van-1.2.3.js:119:10
    at Module.replace (van-x.js:113:16)
    at onFilesAdded (posts.js:142:8)
runAndCaptureDeps @ van-1.2.3.js:17
bind @ van-1.2.3.js:74
add @ van-1.2.3.js:94
(anonymous) @ van-1.2.3.js:119
replace @ van-x.js:113
onFilesAdded @ posts.js:142
onchange @ posts.js:33

van-x.js:112 Uncaught TypeError: Failed to execute 'insertBefore' on 'Node': parameter 1 is not of type 'Node'.
    at Module.replace (van-x.js:112:23)
    at onFilesAdded (posts.js:142:8)
    at HTMLInputElement.onchange (posts.js:33:90)
replace @ van-x.js:112
onFilesAdded @ posts.js:142
onchange @ posts.js:33

To prevent this, AFAICT I'd have to keep a separate File[] array and a my custom File-clone type and keep a vanx.Reactive<MyFileType> sync'd with the sibling File[] array. Doable, but enough of a situation to prompt the question whether you have any idea what causes this, whether there might be a nifty trick for the vanX lib user to employ for certain "browser-native/resource objects" where that would happen, etc. Eager to hear your thoughts =)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions