Skip to content

Conversation

@willhuang1997
Copy link
Contributor

@willhuang1997 willhuang1997 commented Apr 19, 2023

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.

paths:
- lib/streamlit
- frontend/src
paths-ignore:
Copy link
Contributor Author

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}",
Copy link
Contributor Author

@willhuang1997 willhuang1997 Apr 19, 2023

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
Copy link
Contributor Author

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.

Copy link
Contributor

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/
Copy link
Contributor Author

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.

@willhuang1997 willhuang1997 marked this pull request as ready for review April 19, 2023 10:07
@willhuang1997 willhuang1997 added the security-assessment-completed Security assessment has been completed for PR label Apr 19, 2023
Copy link
Contributor

@tconkling tconkling left a 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
Copy link
Contributor

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", () => ({
Copy link
Contributor

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?

Comment on lines 21 to 24
// 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"
Copy link
Contributor

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?

Comment on lines 25 to 27
// 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
Copy link
Contributor

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 test command in package.json uses the --experimental-worker node option, which is required to make Bokeh tests work."

Copy link
Contributor

@tconkling tconkling left a 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!

@tconkling
Copy link
Contributor

(Oh, looks like the CodeQL ignore rules need to be updated for the Bokeh move into src/vendor)

Copy link
Collaborator

@vdonato vdonato left a 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

@willhuang1997 willhuang1997 merged commit b8175e4 into develop Apr 19, 2023
tconkling added a commit to tconkling/streamlit that referenced this pull request Apr 19, 2023
* develop:
  Add Bokeh as a side effect import to modify globals instead of having it in index.html(streamlit#6512)
@vdonato vdonato deleted the refactorBokeh branch November 2, 2023 00:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

security-assessment-completed Security assessment has been completed for PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants