Skip to content

Commit 97a8bc2

Browse files
committed
fix(ud): Add context wrapping to Cedar Functions (#2059)
1 parent ba6c72a commit 97a8bc2

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

packages/vite/src/plugins/vite-plugin-cedar-universal-deploy.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,15 @@ async function generateFunctionModule(distPath: string): Promise<string> {
476476
export default {
477477
async fetch(request) {
478478
const ctx = await buildCedarContext(request);
479-
return _handler(request, ctx);
479+
// Wrap the handler in an AsyncLocalStorage run so the global
480+
// @cedarjs/context is available inside it (and isolated per request).
481+
// Mirrors the GraphQL module above and the cedarContextWrappingPlugin
482+
// used for non-UD builds.
483+
const { getAsyncStoreInstance } = await import(
484+
'@cedarjs/context/dist/store'
485+
);
486+
const store = getAsyncStoreInstance();
487+
return store.run(new Map(), () => _handler(request, ctx));
480488
}
481489
};
482490
`

0 commit comments

Comments
 (0)