-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
Cleanup spaces plugin #91976
Cleanup spaces plugin #91976
Changes from 16 commits
fad2f42
388206d
dc49b70
25a9066
97cc9bb
4ad077f
f022c4c
59a921c
6284843
0872427
9341c0c
0080228
f3126fd
9b6cf54
c922c54
b8d93b0
6242d1a
a21ca9a
032b5cb
bebf3b2
b792353
181ddcb
2612620
1b6554b
1b6c5e5
38fb012
99ab44c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
|
||
import React, { FC, useState } from 'react'; | ||
|
||
import { EuiButtonEmpty } from '@elastic/eui'; | ||
import { EuiButtonEmpty, EuiLoadingSpinner } from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
import type { ShareToSpaceFlyoutProps } from 'src/plugins/spaces_oss/public'; | ||
import { | ||
|
@@ -66,7 +66,9 @@ export const JobSpacesList: FC<Props> = ({ spacesApi, spaceIds, jobId, jobType, | |
}); | ||
} | ||
|
||
const { SpaceList, ShareToSpaceFlyout } = spacesApi.ui.components; | ||
const LazySpaceList = React.lazy(spacesApi.ui.components.getSpaceList); | ||
const LazyShareToSpaceFlyout = React.lazy(spacesApi.ui.components.getShareToSpaceFlyout); | ||
|
||
const shareToSpaceFlyoutProps: ShareToSpaceFlyoutProps = { | ||
savedObjectTarget: { | ||
type: ML_SAVED_OBJECT_TYPE, | ||
|
@@ -81,11 +83,11 @@ export const JobSpacesList: FC<Props> = ({ spacesApi, spaceIds, jobId, jobType, | |
}; | ||
|
||
return ( | ||
<> | ||
<React.Suspense fallback={<EuiLoadingSpinner />}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suspense will throw an error if the lazy component cannot be loaded so you might want to wrap this in an error boundary and create a fallback. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This component is only rendered if the Spaces plugin is enabled and the Spaces API is available, and the getters to lazy load these components ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As discussed offline -- this is necessary if the user runs into any network errors at load time 😅 I'll add wrappers for these that display a toast message so the whole page doesn't blow up. Edit: done in 032b5cb. |
||
<EuiButtonEmpty onClick={() => setShowFlyout(true)} style={{ height: 'auto' }}> | ||
<SpaceList namespaces={spaceIds} displayLimit={0} behaviorContext="outside-space" /> | ||
<LazySpaceList namespaces={spaceIds} displayLimit={0} behaviorContext="outside-space" /> | ||
</EuiButtonEmpty> | ||
{showFlyout && <ShareToSpaceFlyout {...shareToSpaceFlyoutProps} />} | ||
</> | ||
{showFlyout && <LazyShareToSpaceFlyout {...shareToSpaceFlyoutProps} />} | ||
</React.Suspense> | ||
); | ||
}; |
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.
Dynamic imports using
React.lazy
should be created outside the render function, otherwise you're creating a new component with every render ofJobSpacesList
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.
There isn't really anything 'outside' of
render
in a FC 😅 . ButuseMemo
should be used around theReact.lazy
declaration, yea (as it was properly done insaved_objects_table_page.tsx
)Highly depends on the answers on #91976 (comment) though.
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 just pushed some changes.
Wherever I could do so (inside the Spaces plugin) I pulled out the lazy loading to the top level.
Otherwise, I memoized these inside of function components.