Skip to content

Commit 986edeb

Browse files
authored
Merge pull request #21343 from wireapp/fire-and-forget
Migrate MessagesList asset loading to the fire-and-forget invoker [WPB-22420]
2 parents 04366fa + e88e256 commit 986edeb

9 files changed

Lines changed: 372 additions & 368 deletions

File tree

apps/webapp/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"executor": "nx:run-commands",
5656
"dependsOn": ["webapp:stylelint", "webapp:type-check"],
5757
"options": {
58-
"command": "eslint --max-warnings=1032 --ext .js,.ts,.tsx {projectRoot}"
58+
"command": "eslint --max-warnings=1030 --ext .js,.ts,.tsx {projectRoot}"
5959
}
6060
},
6161
"stylelint": {

apps/webapp/src/script/components/FileFullscreenModal/FileEditor/FileEditor.tsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {PrimaryModal} from 'Components/Modals/PrimaryModal';
2727
import {removeCurrentModal} from 'Components/Modals/PrimaryModal/PrimaryModalState';
2828
import {CellsRepository} from 'Repositories/cells/cellsRepository';
2929
import {Config} from 'src/script/Config';
30+
import {useApplicationContext} from 'src/script/page/RootProvider';
3031
import {t} from 'Util/localizerUtil';
3132
import {TIME_IN_MILLIS} from 'Util/timeUtil';
3233

@@ -43,6 +44,7 @@ interface FileEditorProps {
4344

4445
export const FileEditor = ({id}: FileEditorProps) => {
4546
const cellsRepository = container.resolve(CellsRepository);
47+
const {fireAndForgetInvoker} = useApplicationContext();
4648
const [node, setNode] = useState<Node | null>(null);
4749
const [isRecycled, setIsRecycled] = useState(false);
4850
const [isLoading, setIsLoading] = useState(true);
@@ -74,18 +76,19 @@ export const FileEditor = ({id}: FileEditorProps) => {
7476

7577
const handleRetry = useCallback(() => {
7678
hasShownErrorModal.current = false;
77-
void (async () => {
79+
80+
fireAndForgetInvoker.fireAndForget(async (): Promise<void> => {
7881
const isSuccessful = await fetchNode();
7982
if (isSuccessful) {
8083
removeCurrentModal();
8184
}
82-
})();
83-
}, [fetchNode]);
85+
});
86+
}, [fetchNode, fireAndForgetInvoker]);
8487

8588
// Initial fetch
8689
useEffect(() => {
87-
void fetchNode();
88-
}, [id, cellsRepository, fetchNode]);
90+
fireAndForgetInvoker.fireAndForget(fetchNode);
91+
}, [fetchNode, fireAndForgetInvoker]);
8992

9093
// Auto-refresh mechanism before expiry
9194
useEffect(() => {
@@ -98,16 +101,16 @@ export const FileEditor = ({id}: FileEditorProps) => {
98101

99102
// Set timeout to refresh before expiry
100103
const timeoutId = setTimeout(() => {
101-
void fetchNode();
104+
fireAndForgetInvoker.fireAndForget(fetchNode);
102105
}, refreshInSeconds * TIME_IN_MILLIS.SECOND);
103106

104107
return () => {
105108
clearTimeout(timeoutId);
106109
};
107-
}, [node, fetchNode]);
110+
}, [fetchNode, fireAndForgetInvoker, node]);
108111

109112
useEffect(() => {
110-
if (isLoading || isRecycled || (!isError && node)) {
113+
if (isLoading || isRecycled || (!isError && node !== null)) {
111114
return;
112115
}
113116

@@ -134,7 +137,7 @@ export const FileEditor = ({id}: FileEditorProps) => {
134137
}, [handleRetry, isError, isLoading, isRecycled, node]);
135138

136139
useEffect(() => {
137-
if (!isLoading && !isError && node && !isRecycled) {
140+
if (!isLoading && !isError && node !== null && !isRecycled) {
138141
hasShownErrorModal.current = false;
139142
}
140143
}, [isError, isLoading, isRecycled, node]);

0 commit comments

Comments
 (0)