cloudflare / cloudflare/workerd

🐛 Bug Report — binding obtained from global env and DO class property differs in remote dev mode

Open
#4,305 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
8.7k
Forks
739
Avg merge
2d 20h
Merged PRs (30d)
174

Description

In a Durable Object, I'm using a binding. but I also need to access the exact same binding in a nested call that doesn't have access to the Durable Object, and therefore I need to rely on the [global env](https://developers.cloudflare.com/workers/runtime-apis/bindings/#importing-env-as-a-global) to access it.

However, I'm experiencing strange results: the first time I access, both bindings are the exact same object, but when I do a second request they differ.

Here's a way to reproduce the issue:

- create a worker project
- edit `src/index.ts`:

```ts
import { DurableObject } from "cloudflare:workers";

import { env } from 'cloudflare:workers';

export class TestDurableObject extends DurableObject {
constructor(state: DurableObjectState, env: Env) {
super(state, env);
}

fetch(request: Request): Response {
return this.env.BROWSER === env.BROWSER ?
new Response("SAME OBJECT") :
new Response("DIFFERENT OBJECTS!");
}
}

export default {
async fetch(request, env, ctx): Promise {
const id = env.TEST_DO.idFromName('test-instance');
const obj = env.TEST_DO.get(id);
return obj.fetch(request);
},
} satisfies ExportedHandler;
```

- edit `wrangler.jsonc`:

```json
{
"name": "worker-binding-test",
"main": "src/index.ts",
"compatibility_date": "2025-06-10",
"observability": {
"enabled": true
},
"browser": {
"binding": "BROWSER"
},
"durable_objects": {
"bindings": [
{
"name": "TEST_DO",
"class_name": "TestDurableObject"
}
]
},
"migrations": [
{
"tag": "v1",
"new_sqlite_classes": ["TestDurableObject"]
}
],
}
```
- Run with `npx wrangler dev --remote`
- Access http://127.0.0.1:8787/
- renders `SAME OBJECT`
- Refresh the page
- renders `DIFFERENT OBJECTS`, but it should render `SAME OBJECT`

**UPDATE:** This only happens when running in remote dev mode, via `wrangler dev --remote` (browser rendering is only available for dev that way)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.