-
Notifications
You must be signed in to change notification settings - Fork 1.7k
problem with SerializeAddon and globalObject #4424
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
Comments
Does it work, if you just remove the
Background on > function bb() {return this};
< undefined
> bb()
< Window {window: Window, self: Window, document: document, name: '', location: Location, …}
> a={};
< {}
> a.bb = function() {return this;}
< ƒ () {return this;}
> a.bb()
< {bb: ƒ} In the console.log example above function Javascript basically calls any This* bb(This* this) {
return this;
}
// calling bb() directly
bb(window);
// calling a.bb()
bb(a); The reason why Javascript shapeshifts Now what does it all have to do with the global object? In the early days of good old vanilla ECMA3 everything from foreign scripts got hooked into the global object and was accessible from there. The loading is quite simple - the foreign script would see the same top level context, thus anything defined there on top level would get hooked to that one and only window object. This leads to issues for bigger applications loading tons of 3rd party scripts, maybe with clashing/overwriting previous definitions. So ppl invented module encapsulation, and the idea of an Next engines started to implement different global objects and names - Additionally several module loaders were invented (not speaking of ESM, it works quite differently), often putting their loading mechs into functions or methods of its loader objects. But deep nested logic means - its coupled to a custom this object, again tricky to access the real global object for loader, that wants to put things into global scope. (There is some relief - an additional global reference Back to you issue with Sorry for the wall of text. |
Doesn't seem to help. As an experiment, I modified
That allowed me to do what I really want to do:
One idea would be to add to each addon a |
To make sure I understand the issue - does it work for you with a simple ESM is currently not supported w'o re-bundling things yourself, yeah. We have that on the TODO list for quite some time, but it is abit involved for xterm.js, due to complicated TS setup and different browser|headless build targets. The addons though might be a good starter, as they are quite simple in the module structure. In #2878 I suggested something similar to your double bundling idea - ideally we manage to keep the old package format intact to not break current integrations, but just extend the packages with ESM libs and proper export annotations in package.json. |
This is weird. Presumably an artifact of module loading. The following doesn't work:
but this works:
Except for the The reason I used the top-level const declarations to keep the "import-related" code in one place. However, it's not that important. The |
Eww, thats indeed very weird. On which engine did you find that, is that qt embedded QJSEngine? And are you sure, that at the time of your Reasoning behind my questions: Still there is another possible explanation - if you use ESM semantics at the script element (type="module"), the symbols will be only visible within that script context, but not in the global context anymore. Here setting Gonna close the issue - still, if you want to dig deeper, I'd really be interested in the real issue behind that, as it raises more than one eyebrow. |
I don't think this is a bug, but there is an inconsistency between the serialize (and unicode11) addons vs the other addons, because of PR #3421. The
webpack.config.js
files forserialize
andunicode11
containsbut the other addons don't.
To load them I do:
This works if I remove the
globalObject: 'this'
fromxterm-addon-serialize/webpack.config.js
. If I don't remove that line, theSerializeAddon
fails to load. I don't know what to replace thewindow.SerializeAddon.SerializeAddon
with - replacingwindow
bythis
doesn't work.I'm not sure how to fix this. I'm not very knowledgeable about webpack or umd modules.
I can run webpack "manually" (I'm actually using autotools and make to wrap everything) to override the
globalObject
that way. Or perhaps generate EcmaScript modules (which I would prefer anyway), so one idea to run webpack with overrides to generate Es6 modules (type:
module`).BTW: Using the Serialize plugin enables both tmux style session attach/detach, and drag-and-drop of a termnal from one top-level window to another. Both pretty valuable features.
The text was updated successfully, but these errors were encountered: