Skip to content

Commit a053cbd

Browse files
authored
chore(deps): migrate to Svelte 5, Vite 8, and related ecosystem packages (#484)
## Summary Dependabot PRs #475, #480, and #482 all fail because `@sveltejs/vite-plugin-svelte@7.0.0` requires `svelte@^5.46.4` as a peer dependency, but the project uses `svelte@4.2.12`. There is no version of `@sveltejs/vite-plugin-svelte` that supports both Vite 8 and Svelte 4 — the migration must be done together. This PR upgrades both `frontend/` and `cli-releases/frontend/` to Svelte 5 + Vite 8 in one shot. Svelte 5's **compatibility mode** preserves full Svelte 4 component syntax (`export let`, `on:click`, reactive `$:` blocks, etc.), so **no `.svelte` file rewrites are needed**. ### Key changes **frontend/** - svelte 4.2.12 → 5.55.2, vite 5.2.6 → 8.0.8, @sveltejs/vite-plugin-svelte 3.0.2 → 7.0.0 - svelte-chartjs 3.1.5 → 4.0.1, vite-plugin-static-copy 1.0.2 → 4.0.1 - Drop `svelte-preprocess` in favor of `vitePreprocess` from `@sveltejs/vite-plugin-svelte` - Pin `@dfinity/candid@1.0.1` via overrides (pre-existing transitive peer conflict with `@dfinity/agent@1.0.1` — without this, npm resolves candid@2.x which is ABI-incompatible) - Enable `compatibility.componentApi: 4` — the entry point and `svelte-spa-history-router` use `new Component()` which is invalid in Svelte 5 without this flag **cli-releases/frontend/** - svelte 4.2.12 → 5.55.2, vite 5.4.21 → 8.0.8, @sveltejs/vite-plugin-svelte 3.0.2 → 7.0.0 - @sveltejs/kit 2.55.0 → 2.57.1 (adds explicit Vite 8 support) - No `compatibility.componentApi` needed — cli-releases components don't use `export let` **Both projects:** svelte-check 3→4, eslint-plugin-svelte 2.35→2.46 (adds Svelte 5 peer support) ### Additional fixes discovered during staging verification - **Svelte 5 CSS scoping**: `<style global>` is deprecated — replaced with `<style>` and `:global()` wrappers in `App.svelte` to preserve global styles - **Vite 8 `process.env` polyfill**: Added `"process.env": "({})"` fallback in `vite.config.ts` — Vite 8 no longer auto-polyfills `process.env`, causing `ReferenceError` on package detail pages - **`MOPS_NETWORK` staging fix**: Changed `Package.svelte` to set `MOPS_NETWORK` to `"ic"` for all non-local deployments — previously the `ic-mops` npm package used hardcoded staging canister IDs when `DFX_NETWORK=staging`, causing "Package not found" errors - **`fetchRootKey` guard**: Tightened `declarations/main/index.js` and `declarations/bench/index.js` to only call `fetchRootKey()` for `DFX_NETWORK === "local"` (was `!== "ic"`, which unnecessarily triggered for staging) - **`ConfigDoc.svelte` cleanup**: Added `<thead>`/`<tbody>` for semantic HTML, removed commented-out table rows - **`import type` fixes**: Changed all `.did.js` type imports to use `import type` (required by Svelte 5's stricter TypeScript handling) ### Security advisories addressed - vite <=6.4.1 (esbuild vulnerability) - vite-plugin-static-copy 0.4.3–2.3.1 (GHSA-pp7p-q8fx-2968, path traversal) ### Supersedes - #475 (closed) - #480 - #482 ## Test plan - [x] CI passes: `npm ci` + `ci:postinstall` resolves without ERESOLVE errors (all 23 checks green) - [x] `npm run lint` passes - [x] Frontend builds successfully (`npm run build-frontend`) - [x] CLI releases frontend builds (`npm run build-cli-releases`) - [x] CLI tests pass (11 suites, 69 tests, 52 snapshots) - [x] Bundle smoke test passes (verified in CI) - [x] Frontend dev server loads with production canister — no runtime errors - [x] CLI releases frontend serves pre-built assets correctly - [x] Staging deploy verified: homepage (272 packages), package detail pages (/core, /vector), correct fonts/styles, no console errors
1 parent 93aedfc commit a053cbd

35 files changed

Lines changed: 4301 additions & 3260 deletions
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
---
2+
name: frontend-testing
3+
description: Test frontend changes end-to-end and deploy to staging for verification. Use when testing frontend PRs, verifying frontend migrations, testing UI changes, or when the user asks to test the frontend before production. Covers automated checks, local dev server testing, staging deployment, and browser-based verification.
4+
---
5+
6+
# Frontend Testing
7+
8+
Full testing workflow for frontend changes. The agent runs automated checks and local dev server tests (Phases 1–2), then hands off deployment to the human (Phase 3), and finally verifies the deployed app via the browser MCP (Phase 4).
9+
10+
## Phase 1: Automated Checks
11+
12+
Run from the repo root:
13+
14+
```bash
15+
npm run lint
16+
npm run build-frontend
17+
npm run build-cli-releases
18+
```
19+
20+
All must pass before proceeding. Fix any failures introduced by the frontend changes.
21+
22+
## Phase 2: Local Dev Server Testing
23+
24+
Kill anything on ports 3000/3001 to avoid conflicts:
25+
26+
```bash
27+
lsof -ti:3000,3001 | xargs kill -9 2>/dev/null; echo "ports cleared"
28+
```
29+
30+
Start the main frontend dev server (from repo root):
31+
32+
```bash
33+
cd frontend && DFX_NETWORK=ic npx vite --port 3000
34+
```
35+
36+
Start the cli-releases frontend (from repo root, in a separate terminal):
37+
38+
```bash
39+
cd cli-releases/frontend && npx vite preview --port 3001
40+
```
41+
42+
### What to check
43+
44+
1. **No runtime errors** in the Vite terminal output — look for `[vite] (client)` error lines. Warnings (unused CSS selectors, a11y hints) are acceptable.
45+
2. **HTML shell serves**`curl -s http://localhost:3000/` returns HTML with `<div id="root">`. Same for `http://localhost:3001/`.
46+
3. **SPA routes serve**`curl -s -o /dev/null -w "%{http_code}" http://localhost:3000/core` returns 200.
47+
48+
**Do NOT use the browser MCP on localhost** — the embedded browser shows a blank page for this SPA on the Vite dev server. Browser-based verification happens in Phase 4 against the deployed staging build.
49+
50+
Kill the dev servers after checks pass.
51+
52+
## Phase 3: Deploy to Staging (Human)
53+
54+
**This phase must be run by the human in their terminal.** The agent cannot reliably run `dfx deploy` due to a `ColorOutOfRange` TTY panic in dfx v0.29.1 within Cursor's shell, and potential macOS keychain prompts for identity access.
55+
56+
Print the following instructions for the human and wait for confirmation before proceeding to Phase 4.
57+
58+
---
59+
60+
### Instructions for the human
61+
62+
Deploy the frontend to the staging `assets` canister.
63+
64+
**Prerequisites**:
65+
- `dfx` installed via `dfxvm`
66+
- `dfx identity` with controller access to staging canisters (e.g. `mops`)
67+
- Dependencies installed (`npm install` in repo root)
68+
69+
**Important**: `dfxvm` automatically uses the dfx version pinned in `dfx.json`. Do NOT run `dfxvm update`, `dfxvm install`, or `dfxvm default` to "fix" the version — this is correct behavior.
70+
71+
**Run from the repo root:**
72+
73+
```bash
74+
dfx deploy assets --network staging -y
75+
```
76+
77+
After deployment, tell the agent to continue with Phase 4 verification.
78+
79+
---
80+
81+
## Phase 4: Verify Staging Deploy
82+
83+
The staging URL is: **https://ogp6e-diaaa-aaaam-qajta-cai.icp0.io**
84+
85+
This phase can be done by the agent (via browser MCP), the human (manually), or both.
86+
87+
### Agent verification (browser MCP)
88+
89+
Use `user-browsermcp` to verify the deployed build:
90+
91+
1. Navigate to the staging URL, wait 5s, take a snapshot
92+
2. **Check package count** — "Total packages" must show a non-zero number and packages should be listed on the homepage.
93+
3. Click into a package — verify tabs render: Code, Docs, Readme, Versions, Dependencies, Dependents, Tests, Benchmarks
94+
4. Check `browser_console_messages` — no `process is not defined` or `Package not found` errors. `Invalid asm.js` warnings are pre-existing and acceptable.
95+
5. Navigate back to homepage — verify layout, fonts, and styling look correct
96+
97+
### Human verification
98+
99+
Give the human the staging link and ask them to visually compare with production:
100+
101+
- **https://ogp6e-diaaa-aaaam-qajta-cai.icp0.io** (staging)
102+
- **https://mops.one** (production)
103+
104+
Key things to check: fonts, button styles, layout, package detail pages, search.
105+
106+
### Troubleshooting
107+
108+
- **Page blank or doesn't load**: Check `dfx canister status assets --network staging` for cycle balance.
109+
- **`Package not found` errors**: The `ic-mops` npm package may be querying the wrong backend. Ensure the code has `window.MOPS_NETWORK` set to `"ic"` for non-local deployments (see `frontend/components/package/Package.svelte`).

0 commit comments

Comments
 (0)