feat(bake): handle bundle errors, re-assemble full client payloads, initial error modal (#14504)

This commit is contained in:
dave caruso
2024-10-14 16:49:38 -07:00
committed by GitHub
parent 29d287261b
commit d2fe1ce1c8
27 changed files with 2596 additions and 1317 deletions

View File

@@ -303,19 +303,31 @@ class AsyncResource {
// The rest of async_hooks is not implemented and is stubbed with no-ops and warnings.
function createWarning(message) {
function createWarning(message, isCreateHook?: boolean) {
let warned = false;
var wrapped = function () {
var wrapped = function (arg1?) {
if (warned) return;
const known_supported_modules = [
// the following do not actually need async_hooks to work properly
"zx/build/core.js",
"datadog-core/src/storage/async_resource.js",
"react-server-dom-webpack/",
];
const e = new Error().stack!;
if (known_supported_modules.some(m => e.includes(m))) return;
if (isCreateHook && arg1) {
// this block is to specifically filter out react-server, which is often
// times bundled into a framework or application. Their use defines three
// handlers which are all TODO stubs. for more info see this comment:
// https://github.com/oven-sh/bun/issues/13866#issuecomment-2397896065
if (typeof arg1 === 'object') {
const { init, promiseResolve, destroy } = arg1;
if (init && promiseResolve && destroy) {
if (isEmptyFunction(init) && isEmptyFunction(destroy))
return;
}
}
}
warned = true;
console.warn("[bun] Warning:", message);
@@ -323,13 +335,21 @@ function createWarning(message) {
return wrapped;
}
function isEmptyFunction(f: Function) {
let str = f.toString();
if(!str.startsWith('function()'))return false;
str = str.slice('function()'.length).trim();
return /^{\s*}$/.test(str);
}
const createHookNotImpl = createWarning(
"async_hooks.createHook is not implemented in Bun. Hooks can still be created but will never be called.",
true,
);
function createHook(callbacks) {
return {
enable: createHookNotImpl,
enable: () => createHookNotImpl(callbacks),
disable: createHookNotImpl,
};
}