Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit f8735fb

Browse files
committed
Use react lazy to load rte component
1 parent 910aa0b commit f8735fb

File tree

4 files changed

+46
-2
lines changed

4 files changed

+46
-2
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Copyright 2022 The Matrix.org Foundation C.I.C.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import React, { ComponentProps, lazy, Suspense } from "react";
18+
19+
const SendComposer = lazy(() => import("./SendWysiwygComposer"));
20+
const EditComposer = lazy(() => import("./EditWysiwygComposer"));
21+
22+
export function DynamicImportSendWysiwygComposer(props: ComponentProps<typeof SendComposer>) {
23+
return (
24+
<Suspense fallback={<div />}>
25+
<SendComposer {...props} />
26+
</Suspense>
27+
);
28+
}
29+
30+
export function DynamicImportEditWysiwygComposer(props: ComponentProps<typeof EditComposer>) {
31+
return (
32+
<Suspense fallback={<div />}>
33+
<EditComposer {...props} />
34+
</Suspense>
35+
);
36+
}

src/components/views/rooms/wysiwyg_composer/EditWysiwygComposer.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,6 @@ export function EditWysiwygComposer({ editorStateTransfer, className, ...props }
7272
)
7373
);
7474
}
75+
76+
// Needed for React.lazy
77+
export default EditWysiwygComposer;

src/components/views/rooms/wysiwyg_composer/SendWysiwygComposer.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,6 @@ export function SendWysiwygComposer({
7272
</Composer>
7373
);
7474
}
75+
76+
// Needed for React.lazy
77+
export default SendWysiwygComposer;

src/components/views/rooms/wysiwyg_composer/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
export { SendWysiwygComposer } from "./SendWysiwygComposer";
18-
export { EditWysiwygComposer } from "./EditWysiwygComposer";
17+
export {
18+
DynamicImportSendWysiwygComposer as SendWysiwygComposer,
19+
DynamicImportEditWysiwygComposer as EditWysiwygComposer,
20+
} from "./DynamicImportWysiwygComposer";
1921
export { sendMessage } from "./utils/message";

0 commit comments

Comments
 (0)