-
Notifications
You must be signed in to change notification settings - Fork 134
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
Fallback to CDN imports when libraries needed by FileAttachment are not detected through static analysis #1575
Comments
I think I'm in favor of option 2 "add a copy of these libraries even if we don’t detect that they’re used". Self-hosting is a great feature, so option 1 is my least favorite (still better than option 0 = doing nothing, though). Option 3 could be good too, but it feels like more work and would only cover "easy" cases; for example I don't think we would be able to cover the (contrived) case where you have a FileAttachment and a select dropdown that allows the user to choose what method they want to apply to read it. (Not that we should cover this particular case, but who knows what people will invent—a binary file reader app, maybe?) But maybe I'm not seeing the drawback with option 2. Is your comment on "hosting copies of unused libraries" about the unnecessary file size, or about some other reason (like opening a door to some kind of mischievous access)? |
We already rejected this option previously. (Yuri complained about it.) So I don’t think we’ll do that. |
I don't think I'd mind so much if the libraries were smaller, but some of them are quite large indeed. For example, Including these dependencies unconditionally without a way to turn that behavior off would also make it hard to post-process |
DuckDB-Wasm is ~50MB which is even bigger, too. (Edit: Though it’s not in the current set of libraries that need implicit imports by FileAttachment. There was discussion about adding a duckdb method though.) |
To clarify, these files would belong to the build, but they should not be loaded (nor bundled nor preloaded) by pages that don't use them. So for a viewer it should not change anything. The only additional costs are for the site owner: the time to upload the build, and the weight of hosting more bytes. |
The
FileAttachment
methods have implicit imports:FileAttachment.dsv
,FileAttachment.csv
, andFileAttachment.tsv
usenpm:d3-dsv
.FileAttachment.arrow
usesnpm:apache-arrow
.FileAttachment.parquet
usesnpm:apache-arrow
andnpm:parquet-wasm
.FileAttachment.arquero
usesnpm:arquero
, and maybenpm:apache-arrow
andnpm:parquet-wasm
.FileAttachment.sqlite
usesobservablehq:stdlib/sqlite
.FileAttachment.zip
usesobservablehq:stdlib/zip
.FileAttachment.xlsx
usesobservablehq:stdlib/xlsx
.Normally we detect these through static analysis, but we can’t guarantee that we always detect which methods are used through static analysis. For example see https://talk.observablehq.com/t/404-errors-in-module-load/9623. A trivial example where static analysis fails is:
When static analysis fails, built sites currently break because they try to load the self-hosted copy of the library (which doesn’t exist because we only host copies of libraries that we know are used). Perhaps we should fallback to jsDelivr instead, so at least the site keeps working?
Alternatively, we could add a copy of these libraries even if we don’t detect that they’re used, but I don’t think people will like hosting copies of unused libraries.
Alternatively, we could make the static analysis heuristic more lax, for example looking for
file.csv()
calls and not justFileAttachment("name.csv").csv()
calls, but that could have false positives.Related #1574.
The text was updated successfully, but these errors were encountered: