From 9c664218bd18202fbcf778e715bb1baf51cebcff Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Vojt=C4=9Bch=20Tranta?= <vojta.tranta@gmail.com>
Date: Wed, 5 Mar 2025 15:17:26 +0100
Subject: [PATCH 1/6] fix(suite): increase static files cache duration to 30
 days

---
 .github/workflows/release-suite-desktop-web-staging.yml | 2 +-
 .github/workflows/test-transport.yml                    | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/.github/workflows/release-suite-desktop-web-staging.yml b/.github/workflows/release-suite-desktop-web-staging.yml
index fd003f41ad7..dd3d7110544 100644
--- a/.github/workflows/release-suite-desktop-web-staging.yml
+++ b/.github/workflows/release-suite-desktop-web-staging.yml
@@ -133,7 +133,7 @@ jobs:
       - name: Upload suite-desktop to staging-data.trezor.io canary
         # uploads the files to the staging bucket canary  folder (canary does not have staging percentage set)
         run: |
-          aws s3 sync --delete ./trezor-suite-files s3://staging-data.trezor.io/suite/releases/desktop/canary
+          aws s3 sync --delete ./trezor-suite-files s3://staging-data.trezor.io/suite/releases/desktop/canary --cache-control "max-age=2592000"
 
       - name: Set staging percentage
         working-directory:
diff --git a/.github/workflows/test-transport.yml b/.github/workflows/test-transport.yml
index 95cd52195df..fc45594a2ae 100644
--- a/.github/workflows/test-transport.yml
+++ b/.github/workflows/test-transport.yml
@@ -107,4 +107,4 @@ jobs:
           echo "DEPLOY_PATH is set to ${DEPLOY_PATH}"
           mkdir -p tmp_build_directory
           cp -R ./packages/transport-test/e2e/dist/* tmp_build_directory/
-          aws s3 sync --delete tmp_build_directory/ "${DEPLOY_PATH}"
+          aws s3 sync --delete tmp_build_directory/ "${DEPLOY_PATH}"  --cache-control "max-age=2592000"

From 6d4cdaa60a953277a5fc49498307b39568c2222c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Vojt=C4=9Bch=20Tranta?= <vojta.tranta@gmail.com>
Date: Wed, 5 Mar 2025 15:58:07 +0100
Subject: [PATCH 2/6] fix(suite-build): add PreloadWebpackPlugin to preload .js
 files needed for app start

---
 packages/suite-build/configs/web.webpack.config.ts |  9 +++++++++
 packages/suite-build/eslint.config.mjs             |  1 +
 packages/suite-build/package.json                  |  1 +
 yarn.lock                                          | 11 +++++++++++
 4 files changed, 22 insertions(+)

diff --git a/packages/suite-build/configs/web.webpack.config.ts b/packages/suite-build/configs/web.webpack.config.ts
index 77881df85fc..4689d24714a 100644
--- a/packages/suite-build/configs/web.webpack.config.ts
+++ b/packages/suite-build/configs/web.webpack.config.ts
@@ -9,6 +9,8 @@ import { FLAGS, routes } from '@suite-common/suite-config';
 import { assetPrefix, isDev } from '../utils/env';
 import { getPathForProject } from '../utils/path';
 
+const PreloadWebpackPlugin = require('@vue/preload-webpack-plugin');
+
 const baseDir = getPathForProject('web');
 const config: webpack.Configuration = {
     target: 'browserslist',
@@ -74,6 +76,13 @@ const config: webpack.Configuration = {
             /@trezor\/connect$/,
             '@trezor/connect-web/src/module',
         ),
+        new PreloadWebpackPlugin({
+            rel: 'prefetch',
+            include: 'asyncChunks',
+            // NOTE: only prefetch js files
+            fileWhitelist: [/\.js$/],
+            fileBlacklist: [/_svg\.js$/, /date-fns/, /json\.js/, /suite-data/],
+        }),
         ...(!isDev ? [new CssMinimizerPlugin()] : []),
     ],
 };
diff --git a/packages/suite-build/eslint.config.mjs b/packages/suite-build/eslint.config.mjs
index e4553dfa266..4b0ba80edd8 100644
--- a/packages/suite-build/eslint.config.mjs
+++ b/packages/suite-build/eslint.config.mjs
@@ -14,6 +14,7 @@ export default [
                         '**/webpack/**',
                         '**/builds/**',
                         '**/configs/**',
+                        '@vue/preload-webpack-plugin',
                     ],
                 },
             ],
diff --git a/packages/suite-build/package.json b/packages/suite-build/package.json
index 66c44f35600..ff25b4b7e8d 100644
--- a/packages/suite-build/package.json
+++ b/packages/suite-build/package.json
@@ -25,6 +25,7 @@
         "@suite-common/suite-config": "workspace:*",
         "@trezor/bundler-security": "workspace:*",
         "@trezor/suite": "workspace:*",
+        "@vue/preload-webpack-plugin": "^2.0.0",
         "babel-loader": "^9.1.3",
         "babel-plugin-styled-components": "^2.1.4",
         "copy-webpack-plugin": "^12.0.2",
diff --git a/yarn.lock b/yarn.lock
index 978f07e0c03..b324e2518ea 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -12348,6 +12348,7 @@ __metadata:
     "@types/node-fetch": "npm:^2.6.12"
     "@types/webpack-bundle-analyzer": "npm:^4.7.0"
     "@types/webpack-plugin-serve": "npm:^1.4.6"
+    "@vue/preload-webpack-plugin": "npm:^2.0.0"
     babel-loader: "npm:^9.1.3"
     babel-plugin-styled-components: "npm:^2.1.4"
     copy-webpack-plugin: "npm:^12.0.2"
@@ -14734,6 +14735,16 @@ __metadata:
   languageName: node
   linkType: hard
 
+"@vue/preload-webpack-plugin@npm:^2.0.0":
+  version: 2.0.0
+  resolution: "@vue/preload-webpack-plugin@npm:2.0.0"
+  peerDependencies:
+    html-webpack-plugin: ^5.0.0 || ^4.5.1
+    webpack: ^5.20.0 || ^4.1.0
+  checksum: 10/ddaf1542b2cdece5619eb836c96cc177153b8b1a55833d279358d7042d869e916b461e0fc7e8372504a479b8b8c135885b10738bb9a241c5ae542099deef6341
+  languageName: node
+  linkType: hard
+
 "@vue/shared@npm:3.4.27":
   version: 3.4.27
   resolution: "@vue/shared@npm:3.4.27"

From 9c9c2c76875f772ed32e973e57bbfe243d68ae78 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Vojt=C4=9Bch=20Tranta?= <vojta.tranta@gmail.com>
Date: Thu, 6 Mar 2025 10:41:39 +0100
Subject: [PATCH 3/6] wip: try to run main file on the web directly

---
 packages/suite-web/src/index.ts | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/packages/suite-web/src/index.ts b/packages/suite-web/src/index.ts
index 588a4f8068e..276592325ee 100644
--- a/packages/suite-web/src/index.ts
+++ b/packages/suite-web/src/index.ts
@@ -4,14 +4,13 @@
  * After the div is added, MutationObserver detects the change and adds React app to the DOM.
  */
 
+import { init } from './Main';
+
 const observer = new MutationObserver(() => {
     const appElement = document.getElementById('app');
     if (appElement) {
         observer.disconnect();
-
-        import(/* webpackChunkName: "app" */ './Main')
-            .then(comp => comp.init(appElement))
-            .catch(err => console.error(err)); // Fatal error
+        init(appElement);
     }
 });
 

From aab281db305cd6e8ddfd0b78c7a58e78d1f9cb68 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Vojt=C4=9Bch=20Tranta?= <vojta.tranta@gmail.com>
Date: Thu, 6 Mar 2025 10:59:09 +0100
Subject: [PATCH 4/6] wip split chunks

---
 .../suite-build/configs/base.webpack.config.ts     |  3 +++
 packages/suite-build/configs/web.webpack.config.ts | 14 ++++++++++++++
 2 files changed, 17 insertions(+)

diff --git a/packages/suite-build/configs/base.webpack.config.ts b/packages/suite-build/configs/base.webpack.config.ts
index 6c944965f21..699c4e9afb1 100644
--- a/packages/suite-build/configs/base.webpack.config.ts
+++ b/packages/suite-build/configs/base.webpack.config.ts
@@ -67,16 +67,19 @@ const config: webpack.Configuration = {
                     chunks: 'initial',
                     name: 'react',
                     test: /[\\/]node_modules[\\/]react/,
+                    priority: -10,
                 },
                 vendors: {
                     chunks: 'initial',
                     name: 'vendors',
                     test: /[\\/]node_modules[\\/](?!react)/,
+                    priority: -15,
                 },
                 components: {
                     chunks: 'initial',
                     name: 'components',
                     test: /[\\/]packages[\\/]components[\\/]/,
+                    priority: -20,
                 },
             },
         },
diff --git a/packages/suite-build/configs/web.webpack.config.ts b/packages/suite-build/configs/web.webpack.config.ts
index 4689d24714a..8c7f5a3a32c 100644
--- a/packages/suite-build/configs/web.webpack.config.ts
+++ b/packages/suite-build/configs/web.webpack.config.ts
@@ -21,6 +21,20 @@ const config: webpack.Configuration = {
     resolve: {
         fallback: { vm: require.resolve('vm-browserify') },
     },
+    optimization: {
+        splitChunks: {
+            minSize: 100_000,
+            maxInitialRequests: 2,
+            cacheGroups: {
+                main: {
+                    name: 'main',
+                    test: /main/, // Prioritize `main.js`
+                    chunks: 'all',
+                    priority: 100, // High priority
+                },
+            },
+        },
+    },
     plugins: [
         new CopyWebpackPlugin({
             patterns: ['browser-detection', 'fonts', 'images', 'oauth', 'videos', 'guide/assets']

From 31fa54615d8a361072f6b7ec6e7a9c87c4c4fa12 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Vojt=C4=9Bch=20Tranta?= <vojta.tranta@gmail.com>
Date: Thu, 6 Mar 2025 11:28:57 +0100
Subject: [PATCH 5/6] no defaul cache groups

---
 .../configs/base.webpack.config.ts            | 24 +++++++++----------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/packages/suite-build/configs/base.webpack.config.ts b/packages/suite-build/configs/base.webpack.config.ts
index 699c4e9afb1..27bccd20726 100644
--- a/packages/suite-build/configs/base.webpack.config.ts
+++ b/packages/suite-build/configs/base.webpack.config.ts
@@ -63,24 +63,24 @@ const config: webpack.Configuration = {
     optimization: {
         splitChunks: {
             cacheGroups: {
-                react: {
-                    chunks: 'initial',
-                    name: 'react',
-                    test: /[\\/]node_modules[\\/]react/,
-                    priority: -10,
-                },
+                //     react: {
+                //         chunks: 'initial',
+                //         name: 'react',
+                //         test: /[\\/]node_modules[\\/]react/,
+                //         priority: -10,
+                //     },
                 vendors: {
                     chunks: 'initial',
                     name: 'vendors',
                     test: /[\\/]node_modules[\\/](?!react)/,
                     priority: -15,
                 },
-                components: {
-                    chunks: 'initial',
-                    name: 'components',
-                    test: /[\\/]packages[\\/]components[\\/]/,
-                    priority: -20,
-                },
+                // components: {
+                //     chunks: 'initial',
+                //     name: 'components',
+                //     test: /[\\/]packages[\\/]components[\\/]/,
+                //     priority: -20,
+                // },
             },
         },
         minimizer: [

From f1af5fb5628a34565fc0e8846498dfc4979b3ba5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Vojt=C4=9Bch=20Tranta?= <vojta.tranta@gmail.com>
Date: Thu, 6 Mar 2025 12:14:44 +0100
Subject: [PATCH 6/6] disable prefetch

---
 .../configs/analyze.webpack.config.ts         |  8 ++++
 .../configs/base.webpack.config.ts            | 41 ++++++++-----------
 .../suite-build/configs/web.webpack.config.ts | 30 ++++----------
 yarn.lock                                     | 11 +++--
 4 files changed, 37 insertions(+), 53 deletions(-)
 create mode 100644 packages/suite-build/configs/analyze.webpack.config.ts

diff --git a/packages/suite-build/configs/analyze.webpack.config.ts b/packages/suite-build/configs/analyze.webpack.config.ts
new file mode 100644
index 00000000000..508d55d781c
--- /dev/null
+++ b/packages/suite-build/configs/analyze.webpack.config.ts
@@ -0,0 +1,8 @@
+import webpack from 'webpack';
+import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
+
+const config: webpack.Configuration = {
+    plugins: [new BundleAnalyzerPlugin()],
+};
+
+export default config;
diff --git a/packages/suite-build/configs/base.webpack.config.ts b/packages/suite-build/configs/base.webpack.config.ts
index 27bccd20726..387d197772b 100644
--- a/packages/suite-build/configs/base.webpack.config.ts
+++ b/packages/suite-build/configs/base.webpack.config.ts
@@ -1,4 +1,3 @@
-import { sentryWebpackPlugin } from '@sentry/webpack-plugin';
 import path from 'path';
 import TerserPlugin from 'terser-webpack-plugin';
 import webpack from 'webpack';
@@ -8,16 +7,8 @@ import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
 import { WebpackSecurityCheckPlugin } from '@trezor/bundler-security';
 
 import { suiteVersion } from '../../suite/package.json';
-import {
-    assetPrefix,
-    isAnalyzing,
-    isCodesignBuild,
-    isDev,
-    project,
-    sentryAuthToken,
-} from '../utils/env';
+import { assetPrefix, isAnalyzing, isCodesignBuild, isDev, project } from '../utils/env';
 import { getRevision } from '../utils/git';
-import { getPathForProject } from '../utils/path';
 const gitRevision = getRevision();
 
 /**
@@ -187,21 +178,21 @@ const config: webpack.Configuration = {
                   }),
               ]
             : []),
-        ...(!isDev && sentryAuthToken
-            ? [
-                  sentryWebpackPlugin({
-                      telemetry: false,
-                      org: 'satoshilabs',
-                      project: 'trezor-suite',
-                      authToken: sentryAuthToken,
-                      release: { name: sentryRelease, cleanArtifacts: true },
-                      sourcemaps: {
-                          assets: path.join(getPathForProject(project), 'build', '**'),
-                          ignore: ['static/connect'], // connect does not contain source maps for now
-                      },
-                  }),
-              ]
-            : []),
+        // ...(!isDev && sentryAuthToken
+        //     ? [
+        //           sentryWebpackPlugin({
+        //               telemetry: false,
+        //               org: 'satoshilabs',
+        //               project: 'trezor-suite',
+        //               authToken: sentryAuthToken,
+        //               release: { name: sentryRelease, cleanArtifacts: true },
+        //               sourcemaps: {
+        //                   assets: path.join(getPathForProject(project), 'build', '**'),
+        //                   ignore: ['static/connect'], // connect does not contain source maps for now
+        //               },
+        //           }),
+        //       ]
+        //     : []),
     ],
 };
 
diff --git a/packages/suite-build/configs/web.webpack.config.ts b/packages/suite-build/configs/web.webpack.config.ts
index 8c7f5a3a32c..3228090b24e 100644
--- a/packages/suite-build/configs/web.webpack.config.ts
+++ b/packages/suite-build/configs/web.webpack.config.ts
@@ -9,7 +9,7 @@ import { FLAGS, routes } from '@suite-common/suite-config';
 import { assetPrefix, isDev } from '../utils/env';
 import { getPathForProject } from '../utils/path';
 
-const PreloadWebpackPlugin = require('@vue/preload-webpack-plugin');
+// const PreloadWebpackPlugin = require('@vue/preload-webpack-plugin');
 
 const baseDir = getPathForProject('web');
 const config: webpack.Configuration = {
@@ -21,20 +21,6 @@ const config: webpack.Configuration = {
     resolve: {
         fallback: { vm: require.resolve('vm-browserify') },
     },
-    optimization: {
-        splitChunks: {
-            minSize: 100_000,
-            maxInitialRequests: 2,
-            cacheGroups: {
-                main: {
-                    name: 'main',
-                    test: /main/, // Prioritize `main.js`
-                    chunks: 'all',
-                    priority: 100, // High priority
-                },
-            },
-        },
-    },
     plugins: [
         new CopyWebpackPlugin({
             patterns: ['browser-detection', 'fonts', 'images', 'oauth', 'videos', 'guide/assets']
@@ -90,13 +76,13 @@ const config: webpack.Configuration = {
             /@trezor\/connect$/,
             '@trezor/connect-web/src/module',
         ),
-        new PreloadWebpackPlugin({
-            rel: 'prefetch',
-            include: 'asyncChunks',
-            // NOTE: only prefetch js files
-            fileWhitelist: [/\.js$/],
-            fileBlacklist: [/_svg\.js$/, /date-fns/, /json\.js/, /suite-data/],
-        }),
+        // new PreloadWebpackPlugin({
+        //     rel: 'prefetch',
+        //     include: 'asyncChunks',
+        //     // NOTE: only prefetch js files
+        //     fileWhitelist: [/\.js$/],
+        //     fileBlacklist: [/_svg\.js$/, /date-fns/, /json\.js/, /suite-data/],
+        // }),
         ...(!isDev ? [new CssMinimizerPlugin()] : []),
     ],
 };
diff --git a/yarn.lock b/yarn.lock
index b324e2518ea..8e2057cae6b 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -12363,7 +12363,7 @@ __metadata:
     terser-webpack-plugin: "npm:^5.3.11"
     vm-browserify: "npm:^1.1.2"
     webpack: "npm:^5.97.1"
-    webpack-bundle-analyzer: "npm:^4.10.1"
+    webpack-bundle-analyzer: "npm:^4.10.2"
     webpack-merge: "npm:^6.0.1"
     webpack-nano: "npm:^1.1.1"
     webpack-plugin-serve: "npm:^1.6.0"
@@ -43111,9 +43111,9 @@ __metadata:
   languageName: node
   linkType: hard
 
-"webpack-bundle-analyzer@npm:^4.10.1":
-  version: 4.10.1
-  resolution: "webpack-bundle-analyzer@npm:4.10.1"
+"webpack-bundle-analyzer@npm:^4.10.2":
+  version: 4.10.2
+  resolution: "webpack-bundle-analyzer@npm:4.10.2"
   dependencies:
     "@discoveryjs/json-ext": "npm:0.5.7"
     acorn: "npm:^8.0.4"
@@ -43123,14 +43123,13 @@ __metadata:
     escape-string-regexp: "npm:^4.0.0"
     gzip-size: "npm:^6.0.0"
     html-escaper: "npm:^2.0.2"
-    is-plain-object: "npm:^5.0.0"
     opener: "npm:^1.5.2"
     picocolors: "npm:^1.0.0"
     sirv: "npm:^2.0.3"
     ws: "npm:^7.3.1"
   bin:
     webpack-bundle-analyzer: lib/bin/analyzer.js
-  checksum: 10/bc7bc2c014ba36dfb3f28ef75e3bb4be17ebff092ae713a30392a1d578a73b5d83ed0940b9d12eca6b06e514218d8a1e7cb0610f0b4d74b53425be3f0cc3aea8
+  checksum: 10/cb7ff9d01dc04ef23634f439ab9fe739e022cce5595cb340e01d106ed474605ce4ef50b11b47e444507d341b16650dcb3610e88944020ca6c1c38e88072d43ba
   languageName: node
   linkType: hard