Skip to content

Commit 82f009b

Browse files
peterpeterparkerdskloetdmstrasinskis
authored
build: svelte v5 (#6020)
# Motivation We want to stay up-to-date with the tooling for best practices and security reasons. # Notes We keep, when possible, the deprecated `ComponentType` in the source code because if we move to the new types `Component`, component `ResponsiveTyleRow` starts throwing a typing error in its template `Error: Argument of type 'string' is not assignable to parameter of type 'never'.`. (see [job](https://github.com/dfinity/nns-dapp/actions/runs/13107187031/job/36563870978)) Three screenshots were updated in this PR but, visually do no seem to contains any changes. # TODOs Few features and tests need to be adapted for Svelte v5. Those leftovers were marked with `// TODO: Svelte v5 migration` and have to be resolved at latest before the release which will contains the upgrade but, after this PR is merged. # Changes - Bump Gix-cmp for Svelte v5, Svelte, Vite and Testling-library - Update component types in Tests (to resolve issue `Type 'LegacyComponentType' is not assignable to type 'typeof SvelteComponent`). - Remove `svelte/internal` in vitest config to fix `Error: Your application, or one of its dependencies, imported from 'svelte/internal', which was a private module used by Svelte 4 components that no longer exists in Svelte 5. It is not intended to be public API. If you're a library author and you used 'svelte/internal' deliberately, please raise an issue on https://github.com/sveltejs/svelte/issues detailing your use case.` - Remove global override of `requestAnimationFrame` which leads to error `Cannot assign to read only property 'requestAnimationFrame' of object '#<Object>'` and has been resolved in testing library few month ago according this [comment](testing-library/svelte-testing-library#206 (comment)). - Patch configuration for IC-js libraries `spyOn` that ends in error with `Cannot redefine property` vitest-dev/vitest#5625 (comment) - Mock `animate` (testing-library/svelte-testing-library#284 (comment)) - Update tests using `$on` and `$set` as documented https://svelte.dev/docs/svelte/v5-migration-guide#Components-are-no-longer-classes - Rename test files having to use `$state` for test purpose because "rune is only available inside `.svelte` and `.svelte.js/ts` files" --------- Signed-off-by: David Dal Busco <[email protected]> Co-authored-by: David de Kloet <[email protected]> Co-authored-by: Max Strasinsky <[email protected]>
1 parent 0cda415 commit 82f009b

File tree

68 files changed

+1802
-1639
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1802
-1639
lines changed

frontend/package-lock.json

Lines changed: 1359 additions & 1316 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,37 +38,37 @@
3838
"@peculiar/webcrypto": "^1.5.0",
3939
"@playwright/test": "^1.49.1",
4040
"@rollup/plugin-inject": "^5.0.5",
41-
"@sveltejs/adapter-static": "^3.0.5",
42-
"@sveltejs/kit": "^2.8.3",
43-
"@sveltejs/vite-plugin-svelte": "^3.1.2",
41+
"@sveltejs/adapter-static": "^3.0.8",
42+
"@sveltejs/kit": "^2.20.2",
43+
"@sveltejs/vite-plugin-svelte": "^5.0.3",
4444
"@testing-library/jest-dom": "^6.6.3",
45-
"@testing-library/svelte": "^5.2.6",
46-
"@testing-library/user-event": "^14.5.2",
45+
"@testing-library/svelte": "^5.2.7",
46+
"@testing-library/user-event": "^14.6.1",
47+
"@types/node": "^22.13.13",
4748
"@types/wicg-file-system-access": "^2023.10.5",
48-
"@vitest/coverage-v8": "^3.0.5",
49+
"@vitest/coverage-v8": "^3.0.9",
4950
"autoprefixer": "^10.4.20",
5051
"dotenv": "^16.4.5",
5152
"eslint": "^9.20.1",
5253
"eslint-config-prettier": "^10.0.1",
5354
"eslint-plugin-svelte": "^2.46.1",
5455
"fake-indexeddb": "^6.0.0",
55-
"globals": "^15.15.0",
56+
"globals": "^16.0.0",
5657
"jsdom": "^26.0.0",
5758
"node-fetch": "^3.3.2",
5859
"postcss": "^8.4.47",
5960
"prettier": "^3.5.0",
6061
"prettier-plugin-organize-imports": "^4.1.0",
6162
"prettier-plugin-svelte": "^3.3.3",
6263
"sass": "^1.69.4",
63-
"svelte": "^4.2.19",
64-
"svelte-check": "^4.0.2",
65-
"svelte-preprocess": "^6.0.2",
66-
"svelte2tsx": "^0.7.19",
64+
"svelte": "^5.25.3",
65+
"svelte-check": "^4.1.5",
66+
"svelte-preprocess": "^6.0.3",
6767
"typescript": "^5.2.2",
6868
"typescript-eslint": "^8.24.0",
69-
"vite": "^5.4.6",
70-
"vitest": "^3.0.5",
71-
"vitest-mock-extended": "^2.0.2"
69+
"vite": "^6.2.3",
70+
"vitest": "^3.0.9",
71+
"vitest-mock-extended": "^3.0.1"
7272
},
7373
"type": "module",
7474
"dependencies": {
@@ -77,7 +77,7 @@
7777
"@dfinity/candid": "^2.3.0",
7878
"@dfinity/ckbtc": "next",
7979
"@dfinity/cmc": "next",
80-
"@dfinity/gix-components": "next",
80+
"@dfinity/gix-components": "^6.0.0",
8181
"@dfinity/ic-management": "next",
8282
"@dfinity/identity": "^2.1.3",
8383
"@dfinity/ledger-icp": "next",

frontend/src/lib/components/common/MenuItems.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
layoutMenuOpen,
3030
menuCollapsed,
3131
} from "@dfinity/gix-components";
32-
import type { ComponentType } from "svelte";
32+
import type { Component } from "svelte";
3333
import { cubicIn, cubicOut } from "svelte/easing";
3434
import { scale } from "svelte/transition";
3535
@@ -43,7 +43,7 @@
4343
| typeof IconNeurons
4444
| typeof IconVote
4545
| typeof IconRocketLaunch;
46-
statusIcon?: ComponentType;
46+
statusIcon?: Component;
4747
}[];
4848
$: routes = [
4949
...($ENABLE_PORTFOLIO_PAGE

frontend/src/lib/components/portfolio/StackedCards.svelte

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
<script lang="ts" context="module">
2-
import type { ComponentType, SvelteComponent } from "svelte";
3-
type AnyComponent = ComponentType<SvelteComponent>;
2+
import type { Component } from "svelte";
43
54
export type CardItem = {
6-
component: AnyComponent;
5+
component: Component;
76
props?: Record<string, unknown>;
87
};
98
</script>

frontend/src/lib/components/ui/IcpExchangeRate.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
{:else}
3636
<div class="mobile-only">
3737
1 {$i18n.core.icp} = ${icpPriceFormatted}
38-
</div><div>
38+
</div>
39+
<div>
3940
{$i18n.accounts.token_price_source}
4041
</div>
4142
{/if}

frontend/src/lib/modals/transaction/QrWizardModal.svelte

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@
9494
return { result, identifier, token, amount };
9595
};
9696
97-
export const scanQrCode = async ({
97+
// Using const to export a function is incompatible with Svelte v5
98+
// svelte-ignore unused-export-let
99+
export let scanQrCode = async ({
98100
requiredToken,
99101
}: {
100102
requiredToken: Token;

frontend/src/lib/pages/Portfolio.svelte

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import { getTotalStakeInUsd } from "$lib/utils/staking.utils";
2424
import { getTotalBalanceInUsd } from "$lib/utils/token.utils";
2525
import { TokenAmountV2, isNullish } from "@dfinity/utils";
26+
import type { Component } from "svelte";
2627
2728
export let userTokens: UserToken[] = [];
2829
export let tableProjects: TableProject[];
@@ -124,8 +125,9 @@
124125
.map((project) => project.summary);
125126
126127
let launchpadCards: CardItem[];
127-
$: launchpadCards = snsSummaries.map((summary) => ({
128-
component: LaunchProjectCard,
128+
$: launchpadCards = snsSummaries.map<CardItem>((summary) => ({
129+
// TODO: Svelte v5 migration - fix type
130+
component: LaunchProjectCard as unknown as Component,
129131
props: { summary },
130132
}));
131133

frontend/src/lib/pages/SnsWallet.svelte

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@
3030
: undefined;
3131
3232
let transactions: IcrcWalletTransactionsList;
33-
let wallet: IcrcWalletPage;
3433
35-
const reloadAccount = async () => await wallet.reloadAccount?.();
34+
// TODO: Svelte v5 migration - marked as potentially undefined because of SnsWallet.spec.ts
35+
let wallet: IcrcWalletPage | undefined;
36+
37+
const reloadAccount = async () => await wallet?.reloadAccount?.();
3638
const reloadTransactions = () => transactions?.reloadTransactions?.();
3739
</script>
3840

-660 Bytes
Loading
-566 Bytes
Loading

0 commit comments

Comments
 (0)