Skip to content

Commit 03a1b48

Browse files
authored
Retry loading chunks to make the app more resilient (#29001)
Will also fix some Playwright flakes Signed-off-by: Michael Telatynski <[email protected]>
1 parent ef3bf59 commit 03a1b48

File tree

4 files changed

+25
-8
lines changed

4 files changed

+25
-8
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@
293293
"webpack-bundle-analyzer": "^4.8.0",
294294
"webpack-cli": "^6.0.0",
295295
"webpack-dev-server": "^5.0.0",
296+
"webpack-retry-chunk-load-plugin": "^3.1.1",
296297
"webpack-version-file-plugin": "^0.5.0",
297298
"yaml": "^2.3.3"
298299
},

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,16 @@ import { ISendEventResponse } from "matrix-js-sdk/src/matrix";
1212
// we need to import the types for TS, but do not import the sendMessage
1313
// function to avoid importing from "@vector-im/matrix-wysiwyg"
1414
import { SendMessageParams } from "./utils/message";
15-
import { retry } from "../../../../utils/promise";
1615

17-
// Due to issues such as https://github.com/vector-im/element-web/issues/25277, we add retry
18-
// attempts to all of the dynamic imports in this file
19-
const RETRY_COUNT = 3;
20-
const SendComposer = lazy(() => retry(() => import("./SendWysiwygComposer"), RETRY_COUNT));
21-
const EditComposer = lazy(() => retry(() => import("./EditWysiwygComposer"), RETRY_COUNT));
16+
const SendComposer = lazy(() => import("./SendWysiwygComposer"));
17+
const EditComposer = lazy(() => import("./EditWysiwygComposer"));
2218

2319
export const dynamicImportSendMessage = async (
2420
message: string,
2521
isHTML: boolean,
2622
params: SendMessageParams,
2723
): Promise<ISendEventResponse | undefined> => {
28-
const { sendMessage } = await retry(() => import("./utils/message"), RETRY_COUNT);
24+
const { sendMessage } = await import("./utils/message");
2925

3026
return sendMessage(message, isHTML, params);
3127
};
@@ -55,7 +51,7 @@ export const dynamicImportConversionFunctions = async (): Promise<{
5551
*/
5652
plainToRich(plain: string, inMessageFormat: boolean): Promise<string>;
5753
}> => {
58-
const { richToPlain, plainToRich } = await retry(() => import("@vector-im/matrix-wysiwyg"), RETRY_COUNT);
54+
const { richToPlain, plainToRich } = await import("@vector-im/matrix-wysiwyg");
5955

6056
return { richToPlain, plainToRich };
6157
};

webpack.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
1010
const HtmlWebpackInjectPreload = require("@principalstudio/html-webpack-inject-preload");
1111
const CopyWebpackPlugin = require("copy-webpack-plugin");
1212
const VersionFilePlugin = require("webpack-version-file-plugin");
13+
const { RetryChunkLoadPlugin } = require("webpack-retry-chunk-load-plugin");
1314

1415
// Environment variables
1516
// RIOT_OG_IMAGE_URL: specifies the URL to the image which should be used for the opengraph logo.
@@ -690,6 +691,13 @@ module.exports = (env, argv) => {
690691
templateString: "<%= extras.VERSION %>",
691692
extras: { VERSION },
692693
}),
694+
695+
// Due to issues such as https://github.com/vector-im/element-web/issues/25277 we should retry chunk loading
696+
new RetryChunkLoadPlugin({
697+
cacheBust: `() => Date.now()`,
698+
retryDelay: 500,
699+
maxRetries: 3,
700+
}),
693701
].filter(Boolean),
694702

695703
output: {

yarn.lock

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10085,6 +10085,11 @@ [email protected]:
1008510085
resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.4.2.tgz#a5ce1fb522a588bf2b78ca44c6e6fe5aa5a2b13f"
1008610086
integrity sha512-e9MewbtFo+Fevyuxn/4rrcDAaq0IYxPGLvObpQjiZBMAzB9IGmzlnG9RZy3FFas+eBMu2vA0CszMeduow5dIuQ==
1008710087

10088+
prettier@^2.6.2:
10089+
version "2.8.8"
10090+
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.8.8.tgz#e8c5d7e98a4305ffe3de2e1fc4aca1a71c28b1da"
10091+
integrity sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==
10092+
1008810093
pretty-error@^4.0.0:
1008910094
version "4.0.0"
1009010095
resolved "https://registry.yarnpkg.com/pretty-error/-/pretty-error-4.0.0.tgz#90a703f46dd7234adb46d0f84823e9d1cb8f10d6"
@@ -12411,6 +12416,13 @@ webpack-merge@^6.0.1:
1241112416
flat "^5.0.2"
1241212417
wildcard "^2.0.1"
1241312418

12419+
webpack-retry-chunk-load-plugin@^3.1.1:
12420+
version "3.1.1"
12421+
resolved "https://registry.yarnpkg.com/webpack-retry-chunk-load-plugin/-/webpack-retry-chunk-load-plugin-3.1.1.tgz#44aefc21abd01769ecd07f9a200a58a78caf930c"
12422+
integrity sha512-BKq/7EcelyWUUI6SeBaUKB1G+fSZP0rlxIwRQ+aO6mK5tffljaHdpJ4I2q54rpaaKjSbwbZRQlaITXe93SL9nA==
12423+
dependencies:
12424+
prettier "^2.6.2"
12425+
1241412426
webpack-sources@^3.2.3:
1241512427
version "3.2.3"
1241612428
resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-3.2.3.tgz#2d4daab8451fd4b240cc27055ff6a0c2ccea0cde"

0 commit comments

Comments
 (0)