-
Notifications
You must be signed in to change notification settings - Fork 25
Try to use suspense/lazy #40
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
Temporarily commenting out the other components that were causing problem
Is it working? You will have to complete the missing set of classes (CellData...) |
@jourdain I just updated the initial comment with a write-up of what worked, what didn't work, and what's next. |
Thanks @xhlulu for the detailed update. I'll look into it tomorrow to better handle out of order pipeline update. (The cause of the issues you are seeing of bad initial reset camera and no field update (color)) Regarding your following comment
I don't think it has anything to do with react-vtk-js which is part of your async dependency. This come from the way you use the async part as dependency. My wild guess is that we are still loading the dash_vtk.js library too eagerly which then trigger its async dependency right away. I'm not sure how to prevent such loading if we don't use it. |
Yeah it was because I called |
I think you can merge it like that (without publishing a new version just yet). I just need to make react-vtk-js more flexible in the binding order. |
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.
LGTM
@jourdain I prefer waiting for the new react-vtk-js to be released so i can try it on this branch before merging. this way if there's error in the way I implemented async we can catch it without having to do another PR |
I'm on it... But I'm trying to figure out what is the best way to handle the initialization order issue and how to test/validate it inside react-vtk-js context. |
@xhlulu can you trigger the ci? |
* Change import path * npm run build * Add babel's plugin-syntax-dynamic-import Enables the use of the import function inside react for React.lazy * Add LazyComponents module This exports lazy components which are imported in the respective component scripts. This is needed in order for dash to detect the component and add it to _imports_.py * Update View.react.js to use async component * npm run build * npm run build * npm i && npm run build * install @plotly/webpack-dash-dynamic-import * npm i terser-webpack-plugin --save-dev * Add rules and optimization to webpack.config.js * change terser-webpack-plugin to v2.x * npm run build * Upgrade react-vtk-js to 1.2.2 * npm run build * Remove use of Suspense in View.react.js * npm run build * npm run build * install dash-components-plugins * npm run build * Try to use suspense/lazy (#40) * tried stuff * ok let's go back to where it was before * tried some more stuff that seems to make it work? * set async to true * Add usage simple, simplify import structure * Generalized the async component with a async component builder function Temporarily commenting out the other components that were causing problem * Expand async to more components; usage.py now runs but still white square * Improve naming for clarity * Replace all with async react vtk * Add more components to async-react-vtk, make builder more verbose * Wrap Mesh with lazy/suspense * npm run build * Fix incorrect source map * Add tests for docs tutorials * Move the async import call inside the builder function * npm run build * Tests: Increase sleep time for demo, decrease for tutorials * fix typo in usage-vtk-cfd * update react-vtk-js to 1.4.1 * update generated files * trigger circleci * update react-vtk-js to 1.4.2 * update generated files * trigger ci * Apply black to all tests and usage files * Remove dummy app * Update code to be eslint compliant * run build Co-authored-by: Sebastien Jourdain <[email protected]> * Add async files to manifest.in * update react-vtk-js to 1.4.3 * Upgrade react-vtk-js to 1.5.0 * Remove 🔪 unused module and cache group * npm run build Co-authored-by: Sebastien Jourdain <[email protected]> Co-authored-by: Joseph Damiba <[email protected]>
What was tried
Over the weekend I was able to incorporate
React.lazy
andReact.Suspense
for each of the components. To do that, I created some modules:src/lib/ReactVTK.js
: This module simply imports and export the react-vtk-js library, which is needed in order to use thewebpackChunkName
functionality added in webpack and create aasync-ReactVTK.js
file.src/lib/AsyncReactVTK.js
: This module contains aAsyncComponentBuilder
function. It creates an async function that returns a module-like object, which we can then pass toReact.lazy
without causing errors. Later on (inside the components definition), it gets rendered correctly byReact.Suspense
(in theory only). This is the component builder function I used:dash-vtk/src/lib/AsyncReactVTK.js
Lines 5 to 15 in 4cd17de
(I'm happy to hop on a call to explain how I got to this).
I also brought some modifications to the files:
webpack.config.js
: Some changes inlazy-loading
(see Add async loading to reduce package size #29), no change here. Mostly code for chunk splitting in order to allow async.package.json
: Some changes inlazy-loading
(see Add async loading to reduce package size #29), no change here. Added a few packages that were necessary to use the new webpack optimization.src/lib/components
: Each component here was updated such that the import came fromAsyncReactVTK.js
instead ofreact-vtk-js
, and also the component outputted is wrapped with aReact.Suspense
.dash_vtk/__init__.py
: The following elements were added to_js_dist
in order to load the async fragment:What worked
Rendering the simplest possible app, i.e. an empty

dash_vtk.View
worked with this new approach; no error was found in the console. Moreover, I tried withusage.py
, which yielded this result:So it partially worked in the sense that the cone and the starwars obj were rendered correctly, but not the colored pane in the back.

Moreover, very simple demos like the
synthetic-volume-rendering
andt05_reader
seemed to work as well. Additionally, some apps seem to load after a few seconds, but the intiial view is completely broken (you have to zoom out and drag it around to have the correct view; this didn't happen before):What didn't work
Most of the apps (except maybe two) have problems in some way or another. In many cases, the app is completely broken and can't be used at all. Here are two examples of issues with the apps:
slice-rendering
: Getting this error in the console:volume-rendering
: Getting this error in the console:Not actual async loading
Moreover, I also noticed that when I importdash_vtk
inside an app that doesn't usedash_vtk
at all, it will still loadasync-ReactVTK.js
, which is the new file with 500kb:So although we have correctly implemented async, something inside thereact-vtk-js
initialization code forces this file to still be loaded; unfortunately i do not have insight on that.Next step
So far, @jdamiba and I successfully achieved the suggested approach from a React perspective by using
React.lazy
andReact.Suspense
; we also used the same approach as dash-core-components for loading the components (install extra packages inpackage.json
, add custom webpack commands, usewebpackChunkName
in the import calls, etc), albeit with minor modifications through theAsyncComponentBuilder
function, which I highlight doubt is the cause of the problems here.As a next step, it would be amazing if @jourdain takes a look at this branch (specifically, the new and modified files in
src/lib
) and decide whether more development will be needed (in react-vtk-js or in dash-vtk's JS code) in order to achieve the async functionality that we added in this branch.Furthermore, I think it'd be beneficial if @alexcjohnson @Marc-Andre-Rivet reviews our tentative approach to determine if there's a simple fix that @jdamiba and I missed, or if we are doing something wrong.