-
Notifications
You must be signed in to change notification settings - Fork 16k
[Durable Objects] Add changelog for ctx.id.name support #30843
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lead with your second sentence. The first sentence is confusing to a user - what is "what you see client-side".
|
||
|
|
||
| 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. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| ```js | ||
| export class ChatRoom extends DurableObject { | ||
| async fetch(request) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. feature a RPC method over fetch() |
||
| // 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()`. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. already said so can remove to avoid repeat I would mention something about alarms - we want users to understand that ctx.id.name is something that is available no matter how the DO is invoked. For example, the passing in name as arguement doesnt work for alarms
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| - **`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. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This raises user question of what the limit for DO names are. Let's make sure thats documented |
||
|
|
||
| For more information, refer to the [Durable Object ID documentation](/durable-objects/api/id/#name). | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The note on https://wiki.cfdata.org/spaces/PS/blog/2026/05/15/1406850466/Cloudflare+Observability+Where+we+go+from+here mentions
2026-03-15so should these dates match?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hey @vy-ton did you add the correct link here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
struggling to find what I was looking at, should just confirm @maxmcd when ctx.id.name was first available
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2026-03-15 is the notable date: https://developers.cloudflare.com/durable-objects/api/id/#name