fix(middleware): instantiate locals if the adapter does not

This commit is contained in:
lilnasy 2023-10-10 19:51:02 +00:00
parent a8b979ef40
commit 89fbeb34b8
No known key found for this signature in database
GPG key ID: B09B8AE8D3751F1F

View file

@ -76,7 +76,18 @@ export function createAPIContext({
Object.defineProperty(context, 'locals', {
enumerable: true,
get() {
return Reflect.get(request, clientLocalsSymbol);
let locals = Reflect.get(request, clientLocalsSymbol)
if (locals === undefined) {
locals = {}
Reflect.set(request, clientLocalsSymbol, locals)
}
if (typeof locals !== 'object') {
throw new AstroError(AstroErrorData.LocalsNotAnObject);
}
return locals;
},
set(val) {
if (typeof val !== 'object') {