Skip to content

Commit

Permalink
Prevent race condition in Vercel adapter on Node 18 (#11783)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewp authored and ematipico committed Aug 21, 2024
1 parent 540f38a commit a9415bc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .changeset/smooth-melons-cough.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@astrojs/vercel': patch
---

Prevent race condition with Node 18

Using Node 18 there can be a race condition where polyfill for the `crypto` global is not applied in time. This change ensures the polyfills run first.
5 changes: 3 additions & 2 deletions packages/integrations/vercel/src/serverless/entrypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import {
ASTRO_PATH_PARAM,
} from './adapter.js';

// Run polyfills immediately so any dependent code can use the globals
applyPolyfills();

// Won't throw if the virtual module is not available because it's not supported in
// the users's astro version or if astro:env is not enabled in the project
await import('astro/env/setup')
.then((mod) => mod.setGetEnv((key) => process.env[key]))
.catch(() => {});

applyPolyfills();

export const createExports = (
manifest: SSRManifest,
{ middlewareSecret, skewProtection }: { middlewareSecret: string; skewProtection: boolean },
Expand Down

0 comments on commit a9415bc

Please sign in to comment.