-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
investigate ways to load additional data on demand #3530
Comments
Some investigations: The most straight forward solution is to be able to directly use const moduleData = await import(...); Sadly this does not work out of the box, has several drawbacks and raises security concerns:
Searching further reveals, that we kinda stumbled into an uncommon edge case, where the tooling around TS + CJS output + bundlers fails to deliver a proper handling, if you have multiple targets (we have browsers, electron, nodejs). I found some SO posts from angular peeps, that were able to bridge similar requirements with a mixture of So my idea goes also into that direction:
Plz lets discuss the details, pitfalls or even completely different ideas, as I still might not see the whole picture. (Esp. ESM vs CJS seems to be tricky in TS, not sure yet, how that plays into the idea above.) FYI: @Tyriar, @mofux, @meganrogge, @Eugeny |
IMO Points to consider:
|
I agree, but wonder how we can achieve that in a straight forward way. I actually thought about multiple "loader backends" for electron, node/CJS, browser output or a pure static one, to deal with their specifics in a way bundlers still can handle. We could make the basic interface abstract, so peeps can provide their own implementation (if the standard ones do not fit).
Do you mean like introducing some sort of schemes, as nodejs did with their
As indicated above, I hope avoid that with separate loader packages to be hooked into an xterm.js loader endpoint. Example for electron builds:
Yes, for named colors this could be handled directly at the |
Whenever I look into the ES Module / CJS problem, I hit a point where I feel that public support / tooling is not yet ready. At the current point in time, I'd rather pre-bundle the additional data with the core package or as an addon, instead of building a hacky tooling to deal with the different environments. IMHO the effort for supporting and implementing such a We'll get there eventually -- once we can ship xterm.js as an ES Module exclusively and |
We could avoid the chaos of multiple packages by completely relegating the So:
|
Yes, and kinda the whole ecosystem suffers from that. In theory with full ESM-isation of xterm.js we would not need any tooling in xterm.js at all, since it is a library, where even bundling our npm package "xterm.js" is superfluous. ESM is designed to grab through on declared resources, so things can either be delivered that way directly (yes it just works in browsers transparently), or grabbed during bundling on integrator side for final static assets creation. With all goodies like tree shaking working.
Imho our current addon system cannot reflect the needs here, which are lazy loading of rarely used but data intensive resources in the terminal core. For one we have no lazy addon loading triggered from within the terminal, and second - how would you integrate that into core code? Writing dead endpoints to be grabbed from addon code? This would work, but undermines completely our API idea, as such addons always would have to dig deep into private code. (Or we bloat the API with every single aspect popping up.)
The current use case of "named X11 colors" is not really one, we can just say "nope, not supported". But it revealed the problem underneath. Example - with proper unicode grapheme handling we are likely to need 50-200kB of additional data for different codepage segments, depending on how many unicode flags the code has to evaluate. Here it would be nice to split that data into smaller packages for these code segments to allow lazy loading on demand. This helps with overall package size, startup time and does not bloat the JS engine at runtime with data never needed.
I already tried the mixed ESM/CJS packaging in
Thats a very good idea to start with.
This works once |
I feel like this problem gets solved when we adopt ESM fully, inventing our own thing is probably a waste of time given what it ends up giving us only temporarily. The color names are a special case which we could solve for example by adding an option to inject the colors, or a callback to fetch them, and the embedder handles the async part. |
How is that different from |
I guess I just don't want it to be there permanently or used widely is my main comment because ESM will solve it properly eventually. This is easily to understand than a generic thing imo and doesn't need additional documentation on how to setup general dynamic importing: interface ITerminalOptions {
resolveColor: (name: string) => IColor;
} |
Out of scope, thus closing. |
Coming from #3524.
xterm.js currently has no way to load additional data on demand in the core. We are at "either it is there prebundled - or forget it".
We should investigate, how we can externalize rarely used (blob) data into additional resources, that can be requested on demand. Ideally things cover these aspects:
Sidenote: JSON imports are working for most above, but not all - like ESM currently cannot handle it. A workaround to that might be to use the ESM
import()
function at code level with real JS modules (JSON data written to proper code units). Needs investigation...The text was updated successfully, but these errors were encountered: