Repository navigation
Commit 65eb7f0
fix(void): restore Container Durable Object bindings in the dev server (#696)
Since 1.5.0, an app that uses `void/sandbox` can't reach its Sandbox in
the dev server. `getSandbox()` throws:
```
env: Missing Cloudflare binding 'SANDBOX'.
```
Other Container classes lose their binding too. 1.4.0 works.
Since 8b26dba, the config for `@cloudflare/vite-plugin` 2.0 comes from
`migrateBuiltWranglerConfig()`, which rewrites the binding of each
Container class as `unsafe:durable_object_namespace`. That form is only
for the Worker upload. Miniflare skips unsafe bindings that have no dev
plugin, so the class and its Container still exist in dev, but `env` has
no binding for them.
## Fix
In serve, `void:cloudflare-config` turns these bindings back into
regular `durable-object` bindings. Builds and deploys keep the unsafe
form.
Only the generated binding of a Container class changes. An unsafe
binding in the user's config has the same type, but it may point at
another Worker, even at a class with the same name as a local Container.
Turning it into a local binding would connect it to the local class
instead, or stop workerd from starting if this Worker has no such class.
`docs/guide/sandboxes.md` already describes local development with
Docker, so the docs do not change.
## Not fixed here
These also regressed in 1.5.0:
- `vite preview` with a Sandbox fails with the same error.
- A Container with a Dockerfile `image` outside `void/sandbox` stops the
dev server from starting.
- A Container in an auxiliary Worker stops the dev server from starting.
## Tests
`packages/void/test/unit/plugin-cloudflare-v2.test.ts` runs the real
plugin and Miniflare with a Docker stub, so it needs no Docker. In the
dev server, Container classes and a regular Durable Object are bound,
and unsafe bindings from the user's config are not, including one that
names another Worker's class with the same name as a local Container. In
the build, Container classes keep the unsafe form.
The test fails without the fix, without the Container class check and
without the generated-form check.
## Verification
- `vp test run`: 772 files pass, 1 skipped (15,810 tests pass, 29
skipped).
- `vp run check`: 33/33 pass.
- By hand under `vp dev` with Docker:
- `getSandbox('x')` runs `echo hi`, and the local explorer lists
`SANDBOX`.
- The acceptance route of the `kitchen-sink-sandbox` fixture passes all
12 checks.
- A renamed binding and class, a `defineDurableObject` class with a
Container, and `CLOUDFLARE_ENV` pointing at an environment with only a
`name` also work.
- Not run: a real Cloudflare deploy. The change only runs in serve, and
the test checks the binding forms in the build output.
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>1 parent f10f68a commit 65eb7f0
3 files changed
Lines changed: 138 additions & 1 deletion
File tree
- packages/void
- src
- test/unit
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
109 | 132 | | |
110 | 133 | | |
111 | 134 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
79 | 80 | | |
80 | 81 | | |
81 | 82 | | |
| 83 | + | |
| 84 | + | |
82 | 85 | | |
83 | 86 | | |
84 | 87 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
173 | 173 | | |
174 | 174 | | |
175 | 175 | | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
176 | 287 | | |
177 | 288 | | |
178 | 289 | | |
| |||
0 commit comments