Skip to content

Commit

Permalink
fix: merge Netlify context and Hydrogen context, add waitUntil
Browse files Browse the repository at this point in the history
  • Loading branch information
serhalp committed Aug 30, 2024
1 parent c660cee commit 24ca92a
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,27 @@ import {storefrontRedirect} from '@shopify/hydrogen';
import {broadcastDevReady} from '@netlify/remix-runtime';
import {createAppLoadContext} from '~/lib/context';

const waitUntilNotImplemented = async () => {
console.warn('waitUntil not implemented');
/**
* Hydrogen expects a `waitUntil` function like the one in the workerd runtime:
* https://developers.cloudflare.com/workers/runtime-apis/context/#waituntil.
* Netlify Edge Functions don't have such a function, but Deno Deploy isolates make a best-effort
* attempt to wait for the event loop to drain, so just awaiting the promise here is equivalent.
*/
const waitUntil = async (p: Promise<unknown>): Promise<void> => {
await p;
};

export default async function handler(
request: Request,
// FIXME(serhalp) How is it possible we aren't using this?
_context: Context,
netlifyContext: Context,
): Promise<Response | undefined> {
try {
const env = Netlify.env.toObject();

const waitUntil = waitUntilNotImplemented;
const appLoadContext = await createAppLoadContext(request, env, waitUntil);
const appLoadContext = {
...netlifyContext,
...(await createAppLoadContext(request, env, waitUntil)),
};

if (
!env.SESSION_SECRET &&
Expand Down

0 comments on commit 24ca92a

Please sign in to comment.