-
Notifications
You must be signed in to change notification settings - Fork 4k
Add Bokeh as a side effect import #6512
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
Conversation
| paths: | ||
| - lib/streamlit | ||
| - frontend/src | ||
| paths-ignore: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ignore min.js files for codeql
| "start": "env NODE_OPTIONS=--max_old_space_size=8192 ESLINT_NO_DEV_ERRORS=true craco start", | ||
| "build": "env NODE_OPTIONS=--max_old_space_size=8192 GENERATE_SOURCEMAP=false craco build", | ||
| "buildFast": "env NODE_OPTIONS=--max_old_space_size=8192 GENERATE_SOURCEMAP=false BUILD_AS_FAST_AS_POSSIBLE=true craco build", | ||
| "test": "env NODE_OPTIONS=\"--experimental-worker --max_old_space_size=8192\" craco test --env=./jsdom-polyfill-env.js --runTestsByPath ${TESTPATH}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comments in setupTests.js for why this is needed
Makefile
Outdated
| ./scripts/append_license.sh frontend/src/assets/img/Material-Icons.LICENSE | ||
| ./scripts/append_license.sh frontend/src/assets/img/Open-Iconic.LICENSE | ||
| ./scripts/append_license.sh frontend/public/vendor/bokeh/bokeh-LICENSE.txt | ||
| ./scripts/append_license.sh frontend/src/components/elements/BokehChart/vendor/bokeh-LICENSE.txt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this should move from public/vendor but if it should, I can move it back. I was thinking we don't have it in the index.html so we don't need it there anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's not a huge deal (and others may disagree), but I do think we should keep all vendored files in that top-level vendor/ directory. It's the pattern we're using already, and it also means that there's a simple one-stop shop for anyone trying to figure out what our vendored deps are.
(So: let's move the contents of src/components/elements/BokehChart/vendor into public/vendor)
|
|
||
| # Preloaded, minified js (downloaded via script due to dependencies having | ||
| # issues with babel transpilation). | ||
| frontend/public/vendor/bokeh/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't download the scripts anymore so we don't need.
tconkling
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great! Because there's some non-standard trickiness involved here, the PR could really benefit from clearer, and more complete, explanations of what's happening.
(We didn't have this explanation in the original code, which led to you doing a lot of research that the original Bokeh-in-Streamlit implementor had surely already done but neglected to document. I'd love to avoid that scenario again.)
Also, let's move all the vendored files back up to the top-level vendor directory.
Makefile
Outdated
| ./scripts/append_license.sh frontend/src/assets/img/Material-Icons.LICENSE | ||
| ./scripts/append_license.sh frontend/src/assets/img/Open-Iconic.LICENSE | ||
| ./scripts/append_license.sh frontend/public/vendor/bokeh/bokeh-LICENSE.txt | ||
| ./scripts/append_license.sh frontend/src/components/elements/BokehChart/vendor/bokeh-LICENSE.txt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's not a huge deal (and others may disagree), but I do think we should keep all vendored files in that top-level vendor/ directory. It's the pattern we're using already, and it also means that there's a simple one-stop shop for anyone trying to figure out what our vendored deps are.
(So: let's move the contents of src/components/elements/BokehChart/vendor into public/vendor)
| embed: { | ||
| embed_item: jest.fn(), | ||
| import Bokeh from "./vendor/bokeh.esm.js" | ||
| jest.mock("./vendor/bokeh.esm.js", () => ({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add a comment above the mock statement explaining why these particular mocks are needed?
| // bokeh doesn't play well with babel / cra (https://github.com/bokeh/bokeh/issues/10658) | ||
| // have consumers provide their own bokeh minified implementation | ||
| // bokeh.esm is renamed because has "import main from “./bokeh.esm.js" | ||
| import Bokeh from "./vendor/bokeh.esm" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, thank you for adding this comment! Can you reword it for clarity? Let's be as explicit as possible, so that future readers can understand this decision.
- The first line: "We import Bokeh from a vendored source file, because it doesn't play well with Babel (...)"
- The second line: I don't understand what this means. Is it a complete sentence or part of the previous sentence? Can it be reworded so that someone who has no context can understand?
- Same with the third line - I don't understand what it means. "bokeh.esm is renamed" - renamed from what? (Presumably this means that we've renamed from the file, but let's make that explicit.) Why does "import main from ..." require renaming? What's the problem being solved?
frontend/src/setupTests.js
Outdated
| // needed for BokehChart.test.tsx as we import bokeh scripts that use message channel | ||
| // https://github.com/jsdom/jsdom/issues/2448 | ||
| // need to add --experimental-worker in node options craco test cli command |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment would also benefit from a clarity pass. Generally, sentence fragments and no punctuation isn't an issue in comments. But in this case, these are, I assume, two separate ideas ("We need to add the window.MessageChannel import here because..." and "We need to also add this --experimental-worker param elsewhere because").
Can you:
- Add some punctuation (or an additional line break or whatever) so it's clear that these are two separate things being communicated
- Rework that second point "need to add --experimental-worker". Who needs to add it? (Presumably you've already added it, so it's more "Additionally, we also modified such-and-such file to add such and such params" - it's not an imperative statement that the reader needs to act on.)
- "node options craco test cli command" sounds like a series of disconnected words. My assumption is, you edited a specific file with that specific param in order to get bokeh tests to work. Can this comment instead say something like "Additionally: the
testcommand inpackage.jsonuses the--experimental-workernode option, which is required to make Bokeh tests work."
tconkling
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated comments look great, thanks!
|
(Oh, looks like the CodeQL ignore rules need to be updated for the Bokeh move into |
vdonato
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 for the change to the .github repo
* develop: Add Bokeh as a side effect import to modify globals instead of having it in index.html(streamlit#6512)
This PR is to remove Bokeh in the index.html and add them as sideEffect imports which means mainly mutating global objects. This allows for better lazy loading for bokeh. By removing Bokeh from index.html and the downloading of bokeh scripts, some other github actions and such things had to change.