Skip to content

Commit

Permalink
Fix promise proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
mischnic committed Nov 19, 2024
1 parent 86ec6ee commit 07e35f2
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions crates/next-core/src/next_edge/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,20 @@ pub async fn wrap_edge_entry(
// Turn exports into functions that are also a thenable. This way you can await the whole object
// or exports (e.g. for Components) or call them directly as though they are async functions
// (e.g. edge functions/middleware, this is what the Edge Runtime does).
// Catch promise to prevent UnhandledPromiseRejectionWarning, this will be propagated through
// the awaited export(s) anyway.
let source = formatdoc!(
r#"
self._ENTRIES ||= {{}};
self._ENTRIES[{}] = new Proxy(import('MODULE'), {{
const modProm = import('MODULE');
modProm.catch(() => {{}});
self._ENTRIES[{}] = new Proxy(modProm, {{
get(modProm, name) {{
if (name === "then") {{
return modProm.then.bind(modProm);
return (res, rej) => modProm.then(res, rej);
}}
let result = (...args) => modProm.then((mod) => (0, mod[name])(...args));
result.then = (v) => modProm.then((mod) => v(mod[name]));
result.then = (res, rej) => modProm.then((mod) => mod[name]).then(res, rej);
return result;
}},
}});
Expand Down

0 comments on commit 07e35f2

Please sign in to comment.