Repository navigation
Commit bfdace0
fix: restart the dev server when the wrangler config file changes (#17432)
## Summary
Closes #17429.
The Cloudflare adapter's Vite plugin currently reads the wrangler config
once at `configureServer` time and never re-reads it. Edit
`wrangler.toml`/`wrangler.jsonc` and the platform proxy keeps serving
the stale config until the user manually restarts the dev server.
This PR watches the resolved wrangler config path on the Vite dev
server's watcher. When the file is edited, we call `server.restart()`.
The existing teardown (`closeServer` → `dispose`) tears the shared
platform proxy down, and `configureServer` → `setup` creates a fresh one
— `getPlatformProxy(options)` re-reads the config file on each call, so
the restart alone is enough to pick up the new config.
## What changed
- **`packages/adapter-cloudflare/index.js`** — `setup` now accepts the
Vite dev/preview server and, when it's a dev server with a `watcher`,
resolves the wrangler config path via `unstable_readConfig({ config:
options.configPath })` and installs a `change` listener that calls
`server.restart()` when the resolved config file is touched. Preview
servers have no `watcher`, so they skip the hookup. Resolution via
`unstable_readConfig` means we honour the same resolution rules wrangler
itself uses (`wrangler.toml`, `wrangler.jsonc`, `--config`, etc.).
- **`packages/adapter-cloudflare/index.spec.js`** — two new tests:
- `restarts the dev server when the wrangler config file changes` —
mocks `unstable_readConfig` to return a resolved path, asserts
`server.restart()` is called on the matching change and not on any other
file.
- `does not install a config watcher when wrangler cannot resolve a
config path` — proves we're defensive about the `{ configPath: undefined
}` case.
## Local verification
```
$ ./node_modules/.bin/vitest run index.spec.js
Test Files 1 passed (1)
Tests 8 passed (8)
```
6 existing tests + 2 new, all green. Install was `pnpm install --filter
@sveltejs/adapter-cloudflare` on Node 24 / pnpm 12.
## Notes
- Builds directly on top of #17368 (@glw907, merged 2026-10-14) — the
shared-proxy teardown that this restart relies on landed one minute
before the author filed this issue. The two together give `wrangler
config change → one proxy restart across both dev servers`.
- The listener is attached per-server. If the SSR dev server triggers
the restart, Vite tears both down (SvelteKit SSR + client share the
proxy via `__sveltekit_cloudflare_platform_setup`), and the next `setup`
runs with the fresh config.
- The restart does not debounce — if an editor saves twice in a row,
Vite's own `server.restart()` already queues them.
## Changeset
Added patch changeset for `@sveltejs/adapter-cloudflare`.
cc @teemingc — thanks for the sharp report with the Wrangler file:line
references. If you'd rather drive this yourself I'm happy to close and
move my test coverage into your PR.
🤖 Used Claude Code for the research pass and to cross-check the mock
shapes against existing adapter-cloudflare tests; every assertion signed
off by me.
---------
Co-authored-by: Tee Ming <chewteeming01@gmail.com>1 parent 242149e commit bfdace0
3 files changed
Lines changed: 142 additions & 5 deletions
File tree
- .changeset
- packages/adapter-cloudflare
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
216 | 216 | | |
217 | 217 | | |
218 | 218 | | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
219 | 241 | | |
220 | 242 | | |
221 | 243 | | |
222 | 244 | | |
223 | 245 | | |
224 | 246 | | |
225 | | - | |
226 | | - | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
227 | 250 | | |
228 | 251 | | |
229 | 252 | | |
| |||
241 | 264 | | |
242 | 265 | | |
243 | 266 | | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
244 | 296 | | |
245 | 297 | | |
246 | 298 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | 3 | | |
3 | | - | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
10 | | - | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
109 | 110 | | |
110 | 111 | | |
111 | 112 | | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
112 | 192 | | |
113 | 193 | | |
114 | 194 | | |
| |||
0 commit comments