From 331e0a80b5e63f75c8226ddc93d0b0beefd40de3 Mon Sep 17 00:00:00 2001 From: Gal Schlezinger Date: Mon, 29 Aug 2022 11:42:10 +0300 Subject: [PATCH] [fix] don't use top level await in Edge Functions (#6360) Fixes #6345 --- .changeset/shiny-sloths-juggle.md | 6 ++++++ packages/adapter-netlify/src/edge.js | 5 +++-- packages/adapter-vercel/files/edge.js | 6 +++--- 3 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 .changeset/shiny-sloths-juggle.md diff --git a/.changeset/shiny-sloths-juggle.md b/.changeset/shiny-sloths-juggle.md new file mode 100644 index 000000000000..933975125282 --- /dev/null +++ b/.changeset/shiny-sloths-juggle.md @@ -0,0 +1,6 @@ +--- +'@sveltejs/adapter-vercel': patch +'@sveltejs/adapter-netlify': patch +--- + +Don't use top-level-await, as it is not supported right now diff --git a/packages/adapter-netlify/src/edge.js b/packages/adapter-netlify/src/edge.js index 0acf8a593251..2a478285a71d 100644 --- a/packages/adapter-netlify/src/edge.js +++ b/packages/adapter-netlify/src/edge.js @@ -4,7 +4,7 @@ import { manifest, prerendered } from 'MANIFEST'; const server = new Server(manifest); const prefix = `/${manifest.appDir}/`; -await server.init({ +const initialized = server.init({ // @ts-ignore env: Deno.env.toObject() }); @@ -14,13 +14,14 @@ await server.init({ * @param { any } context * @returns { Promise } */ -export default function handler(request, context) { +export default async function handler(request, context) { if (is_static_file(request)) { // Static files can skip the handler // TODO can we serve _app/immutable files with an immutable cache header? return; } + await initialized; return server.respond(request, { platform: { context }, getClientAddress() { diff --git a/packages/adapter-vercel/files/edge.js b/packages/adapter-vercel/files/edge.js index 652f56cc7908..7549ae15022d 100644 --- a/packages/adapter-vercel/files/edge.js +++ b/packages/adapter-vercel/files/edge.js @@ -2,15 +2,15 @@ import { Server } from 'SERVER'; import { manifest } from 'MANIFEST'; const server = new Server(manifest); - -await server.init({ +const initialized = server.init({ env: process.env }); /** * @param {Request} request */ -export default (request) => { +export default async (request) => { + await initialized; return server.respond(request, { getClientAddress() { return request.headers.get('x-forwarded-for');