Skip to content

Commit d813772

Browse files
authored
Lazyload SearchOrAskAiModal (#1625)
* Lazyload `SearchOrAskAiModal` * Run prettier * Fix import
1 parent dac1a5d commit d813772

File tree

3 files changed

+30
-17
lines changed

3 files changed

+30
-17
lines changed
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
.parcel-cache/
22
node_modules/
3-
_static/main.js
4-
_static/main.js.map
5-
_static/custom-elements.js
6-
_static/custom-elements.js.map
7-
_static/pages-nav.js
8-
_static/pages-nav.js.map
93
_static/styles.css
104
_static/styles.css.map
115
_static/*.woff2
6+
_static/*.js
7+
_static/*.js.map

src/Elastic.Documentation.Site/Assets/web-components/SearchOrAskAi/SearchOrAskAiButton.tsx

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
/** @jsxImportSource @emotion/react */
12
import '../../eui-icons-cache'
2-
import { SearchOrAskAiModal } from './SearchOrAskAiModal'
33
import { useModalActions, useModalIsOpen } from './modal.store'
44
import { useSearchActions, useSearchTerm } from './search.store'
55
import {
@@ -10,10 +10,18 @@ import {
1010
EuiPanel,
1111
EuiTextTruncate,
1212
EuiText,
13+
EuiLoadingSpinner,
1314
} from '@elastic/eui'
1415
import { css } from '@emotion/react'
1516
import * as React from 'react'
16-
import { useEffect } from 'react'
17+
import { useEffect, Suspense, lazy } from 'react'
18+
19+
// Lazy load the modal component
20+
const SearchOrAskAiModal = lazy(() =>
21+
import('./SearchOrAskAiModal').then((module) => ({
22+
default: module.SearchOrAskAiModal,
23+
}))
24+
)
1725

1826
export const SearchOrAskAiButton = () => {
1927
const searchTerm = useSearchTerm()
@@ -30,6 +38,13 @@ export const SearchOrAskAiButton = () => {
3038
max-width: 100%;
3139
`
3240

41+
const loadingCss = css`
42+
display: flex;
43+
justify-content: center;
44+
align-items: center;
45+
padding: 2rem;
46+
`
47+
3348
useEffect(() => {
3449
const handleKeydown = (event: KeyboardEvent) => {
3550
if (event.key === 'Escape') {
@@ -81,7 +96,15 @@ export const SearchOrAskAiButton = () => {
8196
<EuiOverlayMask>
8297
<EuiFocusTrap onClickOutside={closeModal}>
8398
<EuiPanel role="dialog" css={positionCss}>
84-
<SearchOrAskAiModal />
99+
<Suspense
100+
fallback={
101+
<div css={loadingCss}>
102+
<EuiLoadingSpinner size="xl" />
103+
</div>
104+
}
105+
>
106+
<SearchOrAskAiModal />
107+
</Suspense>
85108
</EuiPanel>
86109
</EuiFocusTrap>
87110
</EuiOverlayMask>

src/Elastic.Documentation.Site/Assets/web-components/SearchOrAskAi/SearchOrAskAiModal.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { Suggestions } from './Suggestions'
33
import { useAskAiTerm, useSearchActions, useSearchTerm } from './search.store'
44
import {
55
EuiFieldSearch,
6-
EuiPanel,
76
EuiSpacer,
87
EuiBetaBadge,
98
EuiText,
@@ -20,12 +19,7 @@ export const SearchOrAskAiModal = () => {
2019
const { setSearchTerm, submitAskAiTerm } = useSearchActions()
2120

2221
return (
23-
<EuiPanel
24-
css={css`
25-
max-height: 80vh;
26-
overflow: hidden;
27-
`}
28-
>
22+
<>
2923
<EuiFieldSearch
3024
fullWidth
3125
placeholder="Search the docs or ask Elastic Docs AI Assistant"
@@ -61,6 +55,6 @@ export const SearchOrAskAiModal = () => {
6155
This feature is in beta. Got feedback? We'd love to hear it!
6256
</EuiText>
6357
</div>
64-
</EuiPanel>
58+
</>
6559
)
6660
}

0 commit comments

Comments
 (0)