From 64860fe98329557d23d172df2505d4d6beb0a3ea Mon Sep 17 00:00:00 2001 From: iglesiasbrandon <5313116+iglesiasbrandon@users.noreply.github.com> Date: Fri, 15 May 2026 14:18:40 -0400 Subject: [PATCH] [Durable Objects] Add changelog for ctx.id.name support Add changelog entry dated 2026-03-26 documenting that ctx.id.name is now populated inside a Durable Object when accessed via idFromName() or getByName(), matching the name visible on the client-side stub. --- .../2026-03-26-durable-object-id-name.mdx | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/content/changelog/durable-objects/2026-03-26-durable-object-id-name.mdx diff --git a/src/content/changelog/durable-objects/2026-03-26-durable-object-id-name.mdx b/src/content/changelog/durable-objects/2026-03-26-durable-object-id-name.mdx new file mode 100644 index 00000000000..7e5261e431c --- /dev/null +++ b/src/content/changelog/durable-objects/2026-03-26-durable-object-id-name.mdx @@ -0,0 +1,39 @@ +--- +title: Access Durable Object name via `ctx.id.name` +description: Retrieve the name of a named Durable Object from within the object itself. +products: + - durable-objects + - workers +date: 2026-03-26 +--- + +`ctx.id.name` inside a Durable Object now matches what you see client-side. If a Worker accesses a Durable Object via `idFromName()` or `getByName()`, the same name is now available on `ctx.id.name` inside the object — no need to pass it through method arguments or persist it in storage. + +Previously, the TypeScript type for `ctx.id` declared `name` as `string | undefined`, which led developers and LLM-based coding assistants to assume the name would be available inside the Durable Object. In reality, it was always `undefined` from inside, forcing manual workarounds. + +```js +export class ChatRoom extends DurableObject { + async fetch(request) { + // ctx.id.name now matches the name passed to getByName() or idFromName() on the client side + const roomName = this.ctx.id.name; + return new Response(`Welcome to ${roomName}!`); + } +} + +// Worker +export default { + async fetch(request, env) { + const stub = env.CHAT_ROOM.getByName("general"); + return stub.fetch(request); + }, +}; +``` + +A few things to note about when `ctx.id.name` is set: + +- **Populated** when the Durable Object is accessed via `idFromName()` or `getByName()`. +- **`undefined`** for Durable Objects created with `newUniqueId()`. +- **`undefined`** when accessed via `idFromString()`, even if the ID was originally created from a name. +- **`undefined`** for names longer than 1,024 bytes. + +For more information, refer to the [Durable Object ID documentation](/durable-objects/api/id/#name).