-
Notifications
You must be signed in to change notification settings - Fork 26
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
STCOR-635 wrap pluggable in suspense #1213
base: master
Are you sure you want to change the base?
Conversation
Wrap Pluggable's return value in Suspense in order to avoid whole-tree re-renders, since the whole tree from the components up to the nearest `<Suspense>` is removed and replaced with its fallback. For us, this is particularly a problem when a plugin is part of a dropdown menu that uses calculations to set its position. Because the entire tree will be unmounted, the calculations all return zero, resulting in incorrect placement with zero offset from the let margin (STRWEB-53). h/t @BogdanDenis and @mkuklis for figuring this all out. Refs STCOR-635
BigTest Unit Test Statistics 1 files ±0 1 suites ±0 12s ⏱️ -1s Results for commit e8ddb8a. ± Comparison against base commit 976a95c. This pull request removes 5 and adds 3 tests. Note that renamed tests count towards both.
♻️ This comment has been updated with latest results. |
This is a nice idea, but it doesn't work. In a ui-inventory build with resolutions to this branch and to stripes-webpack with lazy turned back off for plugins,
Interestingly, I also had to add dev-deps for stripes-form and stripes-final-form. @mkuklis , @BogdanDenis , any ideas what could be going on? |
@zburke hmm, I get a completely different error
I'll investigate this more today |
src/Pluggable.js
Outdated
import PropTypes from 'prop-types'; | ||
import { modules } from 'stripes-config'; | ||
import { withStripes } from './StripesContext'; | ||
import { ModuleHierarchyProvider } from './components'; | ||
import { LoadingView, ModuleHierarchyProvider } from './components'; |
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.
@zburke I think <LoadingView>
should come from @folio/stripes/components
. This fixed my webpack error, but I didn't see what you reported in your comment
SonarCloud Quality Gate failed. |
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.
Should use <Loading>
instead - <LoadingView>
will render a <Paneset>
and this can potentially break pane resizing if there's a parent <Paneset>
. Just spent a few hours debugging an issue that was caused by nested panesets, even though in theory they are valid.
I know it was I who suggested using <LoadingView>
- so that's me fixing my mistake here
import PropTypes from 'prop-types'; | ||
import { modules } from 'stripes-config'; | ||
import { withStripes } from './StripesContext'; | ||
import { ModuleHierarchyProvider } from './components'; | ||
import { LoadingView } from '@folio/stripes-components'; |
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.
import { LoadingView } from '@folio/stripes-components'; | |
import { Loading } from '@folio/stripes-components'; |
@@ -37,7 +38,9 @@ const Pluggable = (props) => { | |||
if (cachedPlugins.length) { | |||
return cachedPlugins.map(({ plugin, Child }) => ( | |||
<ModuleHierarchyProvider module={plugin}> | |||
<Child {...props} actAs="plugin" /> | |||
<Suspense fallback={<LoadingView />}> |
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.
<Suspense fallback={<LoadingView />}> | |
<Suspense fallback={<Loading />}> |
@@ -47,7 +50,11 @@ const Pluggable = (props) => { | |||
// eslint-disable-next-line no-console | |||
console.error(`<Pluggable type="${props.type}"> has ${props.children.length} children, can only return one`); | |||
} | |||
return props.children; | |||
return ( | |||
<Suspense fallback={<LoadingView />}> |
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.
<Suspense fallback={<LoadingView />}> | |
<Suspense fallback={<Loading />}> |
@BogdanDenis, we turned off lazy-loading of modules for Morning Glory in stripes-webpack in folio-org/stripes-webpack#69, which should turn |
Yes, since lazy loading is turned off for now we don't need it. Just wanted to comment this so we won't miss this when we decide to turn lazy loading back on and merge this PR Also, I spoke with @JohnC-80 about nested panesets, and he said that they should work, and do work for plugins and settings, so I was wrong about nested panesets causing problems |
Wrap Pluggable's return value in Suspense in order to avoid whole-tree
re-renders, since the whole tree from the components up to the nearest
<Suspense>
is removed and replaced with its fallback. For us, this isparticularly a problem when a plugin is part of a dropdown menu that
uses calculations to set its position. Because the entire tree will be
unmounted, the calculations all return zero, resulting in incorrect
placement with zero offset from the let margin (STRWEB-53).
h/t @BogdanDenis and @mkuklis for figuring this all out.
Refs STCOR-635