Skip to content

Commit ee2c260

Browse files
Add deprecation getters for Astro.locals.runtime (#15075)
* feat(cloudflare): add deprecation getters for Astro.locals.runtime Adds helpful error messages when accessing removed runtime properties: - runtime.env -> import { env } from 'cloudflare:workers' - runtime.cf -> Astro.request.cf - runtime.caches -> global caches object - runtime.ctx -> Astro.locals.cfContext Improves migration experience from v5 to v6. * chore: add changeset for runtime deprecation helpers * Update .changeset/helpful-runtime-errors.md Co-authored-by: Armand Philippot <[email protected]> * fix(cloudflare): hide runtime from types and enumeration - Remove runtime from Runtime interface to prevent autocomplete - Use Object.defineProperty with enumerable: false --------- Co-authored-by: Armand Philippot <[email protected]>
1 parent 4463a55 commit ee2c260

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@astrojs/cloudflare': patch
3+
---
4+
5+
Adds deprecation errors for `Astro.locals.runtime` properties to help migrate from Astro v5 to v6
6+
7+
When accessing the removed `Astro.locals.runtime` properties on Cloudflare, developers now receive clear error messages explaining the migration path:
8+
9+
- `Astro.locals.runtime.env` → Use `import { env } from "cloudflare:workers"`
10+
- `Astro.locals.runtime.cf` → Use `Astro.request.cf`
11+
- `Astro.locals.runtime.caches` → Use the global `caches` object
12+
- `Astro.locals.runtime.ctx` → Use `Astro.locals.cfContext`

packages/integrations/cloudflare/src/utils/handler.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,31 @@ export async function handle(
5959
const locals: Runtime = {
6060
cfContext: context,
6161
};
62+
Object.defineProperty(locals, 'runtime', {
63+
enumerable: false,
64+
value: {
65+
get env(): never {
66+
throw new Error(
67+
`Astro.locals.runtime.env has been removed in Astro v6. Use 'import { env } from "cloudflare:workers"' instead.`,
68+
);
69+
},
70+
get cf(): never {
71+
throw new Error(
72+
`Astro.locals.runtime.cf has been removed in Astro v6. Use 'Astro.request.cf' instead.`,
73+
);
74+
},
75+
get caches(): never {
76+
throw new Error(
77+
`Astro.locals.runtime.caches has been removed in Astro v6. Use the global 'caches' object instead.`,
78+
);
79+
},
80+
get ctx(): never {
81+
throw new Error(
82+
`Astro.locals.runtime.ctx has been removed in Astro v6. Use 'Astro.locals.cfContext' instead.`,
83+
);
84+
},
85+
},
86+
});
6287

6388
const response = await app.render(
6489
request as Request & Parameters<ExportedHandlerFetchHandler>[0],

0 commit comments

Comments
 (0)