Skip to content

Commit 63165f8

Browse files
authored
fix(Assets): remove top-level await (#7741)
Top-level await for `@ui5/webcomponents-fiori/dist/Assets.js`, causes runtime errors in Next.js App Router and could also break Pages Router during SSR or build-time module evaluation.
1 parent 4633f41 commit 63165f8

File tree

3 files changed

+65
-5
lines changed

3 files changed

+65
-5
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,24 @@ npm install @ui5/webcomponents-react @ui5/webcomponents
118118
> import { Button } from '@ui5/webcomponents-react';
119119
> ```
120120
121+
#### Importing Assets
122+
123+
The default assets import (`import '@ui5/webcomponents-react/dist/Assets.js';`) includes assets from the fiori package. Due to a limitation of Next.js (top-level await is not supported), we can't dynamically import the assets based on the installed packages.
124+
If you are using the minimal installation, please import the assets manually as follows:
125+
126+
```ts
127+
import '@ui5/webcomponents/dist/Assets.js';
128+
import '@ui5/webcomponents-react/dist/json-imports/i18n.js';
129+
130+
//fetch
131+
import '@ui5/webcomponents/dist/Assets-fetch.js';
132+
import '@ui5/webcomponents-react/dist/json-imports/i18n-fetch.js';
133+
134+
//node
135+
import '@ui5/webcomponents/dist/Assets-node.js';
136+
import '@ui5/webcomponents-react/dist/json-imports/i18n-node.js';
137+
```
138+
121139
## End of Support for Version 1.x
122140

123141
The support for version 1.x of `ui5-webcomponents-react` has ended on **July 1, 2025**. We recommend migrating to version 2.x as soon as possible. For more information, please refer to our [Migration Guide](https://sap.github.io/ui5-webcomponents-react/v2/?path=/docs/migration-guide--docs).

docs/Welcome.mdx

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,48 @@ Since version `v2.14.0` of `@ui5/webcomponents-react`, `@ui5/webcomponents-fiori
6868
- You want to use the [VariantManagement](https://sap.github.io/ui5-webcomponents-react/v2/?path=/docs/inputs-variantmanagement--docs) component.
6969
- You import anything from the `@ui5/webcomponents-fiori` package.
7070

71-
**Note:** Most popular bundlers enable tree-shaking for production builds, so there’s no difference in the final bundle size between the recommended and minimal installations.
72-
7371
```sh
7472
npm install @ui5/webcomponents-react @ui5/webcomponents
7573
```
7674

75+
**Note:** Most popular bundlers enable tree-shaking for production builds, so there’s no difference in the final bundle size between the recommended and minimal installations.
76+
77+
> ⚠️ **Warning**
78+
>
79+
> If your bundler does **not** support tree-shaking, you must use **subpath imports**.
80+
>
81+
> Otherwise, since `@ui5/webcomponents-react` re-exports all components, **every component** (including those that depend on the `@ui5/webcomponents-fiori` package) will be included in your bundle, which will lead to errors due to the missing module.
82+
>
83+
> **✅ Do:**
84+
>
85+
> ```tsx
86+
> import { Button } from '@ui5/webcomponents-react/Button';
87+
> ```
88+
>
89+
> **❌ Don’t:**
90+
>
91+
> ```tsx
92+
> import { Button } from '@ui5/webcomponents-react';
93+
> ```
94+
95+
##### Importing Assets
96+
97+
The default assets import (`import '@ui5/webcomponents-react/dist/Assets.js';`) includes assets from the fiori package. Due to a limitation of Next.js (top-level await is not supported), we can't dynamically import the assets based on the installed packages.
98+
If you are using the minimal installation, please import the assets manually as follows:
99+
100+
```ts
101+
import '@ui5/webcomponents/dist/Assets.js';
102+
import '@ui5/webcomponents-react/dist/json-imports/i18n.js';
103+
104+
//fetch
105+
import '@ui5/webcomponents/dist/Assets-fetch.js';
106+
import '@ui5/webcomponents-react/dist/json-imports/i18n-fetch.js';
107+
108+
//node
109+
import '@ui5/webcomponents/dist/Assets-node.js';
110+
import '@ui5/webcomponents-react/dist/json-imports/i18n-node.js';
111+
```
112+
77113
### Version Alignment & Package Mapping
78114

79115
<VersionTable />

packages/main/scripts/generateI18n.mjs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ spawnSync('npx', ['prettier', '--write', path.resolve(SRC_I18N_PROPERTIES, 'i18n
5858
// generate Assets.js and Assets-fetch.js
5959
const jsonImports = await readdir(TARGET_I18N_JSON_IMPORTS);
6060

61+
// todo: Next.js does not support top level await
62+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
6163
function createDynamicFioriAssetsImport(suffix) {
6264
return `try {
6365
await import('@ui5/webcomponents-fiori/dist/Assets${suffix}.js');
@@ -66,9 +68,13 @@ function createDynamicFioriAssetsImport(suffix) {
6668
}`;
6769
}
6870

69-
const assets = [`import '@ui5/webcomponents/dist/Assets.js';`, createDynamicFioriAssetsImport('')];
70-
const assetsFetch = [`import '@ui5/webcomponents/dist/Assets-fetch.js';`, createDynamicFioriAssetsImport('-fetch')];
71-
const assetsNode = [`import '@ui5/webcomponents/dist/Assets-node.js';`, createDynamicFioriAssetsImport('-node')];
71+
function createFioriAssetsImport(suffix) {
72+
return `import '@ui5/webcomponents-fiori/dist/Assets${suffix}.js';`;
73+
}
74+
75+
const assets = [`import '@ui5/webcomponents/dist/Assets.js';`, createFioriAssetsImport('')];
76+
const assetsFetch = [`import '@ui5/webcomponents/dist/Assets-fetch.js';`, createFioriAssetsImport('-fetch')];
77+
const assetsNode = [`import '@ui5/webcomponents/dist/Assets-node.js';`, createFioriAssetsImport('-node')];
7278

7379
for (const file of jsonImports) {
7480
if (file.includes('-fetch')) {

0 commit comments

Comments
 (0)