diff --git a/.changeset/eight-ears-call.md b/.changeset/eight-ears-call.md new file mode 100644 index 000000000000..41a9140a7a24 --- /dev/null +++ b/.changeset/eight-ears-call.md @@ -0,0 +1,7 @@ +--- +'@astrojs/preact': patch +'@astrojs/react': patch +'@astrojs/solid-js': patch +--- + +Improves compatability with the [Qwik adapter](https://github.com/QwikDev/astro) diff --git a/.changeset/rare-ants-swim.md b/.changeset/rare-ants-swim.md new file mode 100644 index 000000000000..1bde7bf14258 --- /dev/null +++ b/.changeset/rare-ants-swim.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Improves errors in certain places to also report their causes. diff --git a/packages/astro/src/assets/build/generate.ts b/packages/astro/src/assets/build/generate.ts index 4ee210ec3037..a73ef11f2768 100644 --- a/packages/astro/src/assets/build/generate.ts +++ b/packages/astro/src/assets/build/generate.ts @@ -226,7 +226,6 @@ export async function generateImagesForPath( ...AstroErrorData.CouldNotTransformImage, message: AstroErrorData.CouldNotTransformImage.message(originalFilePath), }, - undefined, { cause: e } ); diff --git a/packages/astro/src/core/errors/errors.ts b/packages/astro/src/core/errors/errors.ts index faf365686908..37373527b03d 100644 --- a/packages/astro/src/core/errors/errors.ts +++ b/packages/astro/src/core/errors/errors.ts @@ -38,10 +38,10 @@ export class AstroError extends Error { type: ErrorTypes = 'AstroError'; - constructor(props: ErrorProperties, ...params: any) { - super(...params); - + constructor(props: ErrorProperties, options?: ErrorOptions) { const { name, title, message, stack, location, hint, frame } = props; + super(message, options); + this.title = title; this.name = name; @@ -81,8 +81,8 @@ export class AstroError extends Error { export class CompilerError extends AstroError { type: ErrorTypes = 'CompilerError'; - constructor(props: ErrorProperties, ...params: any) { - super(props, ...params); + constructor(props: ErrorProperties, options?: ErrorOptions) { + super(props, options); } static is(err: unknown): err is CompilerError { @@ -120,8 +120,8 @@ export class AggregateError extends AstroError { // Despite being a collection of errors, AggregateError still needs to have a main error attached to it // This is because Vite expects every thrown errors handled during HMR to be, well, Error and have a message - constructor(props: ErrorProperties & { errors: AstroError[] }, ...params: any) { - super(props, ...params); + constructor(props: ErrorProperties & { errors: AstroError[] }, options?: ErrorOptions) { + super(props, options); this.errors = props.errors; } diff --git a/packages/astro/src/core/middleware/loadMiddleware.ts b/packages/astro/src/core/middleware/loadMiddleware.ts index 135f7fbc479e..da6090982689 100644 --- a/packages/astro/src/core/middleware/loadMiddleware.ts +++ b/packages/astro/src/core/middleware/loadMiddleware.ts @@ -12,7 +12,7 @@ export async function loadMiddleware(moduleLoader: ModuleLoader) { try { return await moduleLoader.import(MIDDLEWARE_MODULE_ID); } catch (error: any) { - const astroError = new AstroError(MiddlewareCantBeLoaded, undefined, { cause: error }); + const astroError = new AstroError(MiddlewareCantBeLoaded, { cause: error }); throw astroError; } } diff --git a/packages/integrations/preact/src/server.ts b/packages/integrations/preact/src/server.ts index a395433c9bad..7d017a413951 100644 --- a/packages/integrations/preact/src/server.ts +++ b/packages/integrations/preact/src/server.ts @@ -13,6 +13,7 @@ let consoleFilterRefs = 0; function check(this: RendererContext, Component: any, props: Record, children: any) { if (typeof Component !== 'function') return false; + if (Component.name === 'QwikComponent') return false; if (Component.prototype != null && typeof Component.prototype.render === 'function') { return BaseComponent.isPrototypeOf(Component); diff --git a/packages/integrations/react/server-v17.js b/packages/integrations/react/server-v17.js index 5638c6fb776e..ad0c99622b56 100644 --- a/packages/integrations/react/server-v17.js +++ b/packages/integrations/react/server-v17.js @@ -20,6 +20,7 @@ function check(Component, props, children) { return Component['$$typeof']?.toString().slice('Symbol('.length).startsWith('react'); } if (typeof Component !== 'function') return false; + if (Component.name === 'QwikComponent') return false; if (Component.prototype != null && typeof Component.prototype.render === 'function') { return React.Component.isPrototypeOf(Component) || React.PureComponent.isPrototypeOf(Component); diff --git a/packages/integrations/react/server.js b/packages/integrations/react/server.js index 4c1aac9334d4..b3ddeb6b1d12 100644 --- a/packages/integrations/react/server.js +++ b/packages/integrations/react/server.js @@ -22,6 +22,7 @@ async function check(Component, props, children) { return Component['$$typeof'].toString().slice('Symbol('.length).startsWith('react'); } if (typeof Component !== 'function') return false; + if (Component.name === 'QwikComponent') return false; // Preact forwarded-ref components can be functions, which React does not support if (typeof Component === 'function' && Component['$$typeof'] === Symbol.for('react.forward_ref')) diff --git a/packages/integrations/solid/src/server.ts b/packages/integrations/solid/src/server.ts index 6e371da517f6..445e4605e9de 100644 --- a/packages/integrations/solid/src/server.ts +++ b/packages/integrations/solid/src/server.ts @@ -6,6 +6,7 @@ const slotName = (str: string) => str.trim().replace(/[-_]([a-z])/g, (_, w) => w function check(this: RendererContext, Component: any, props: Record, children: any) { if (typeof Component !== 'function') return false; + if (Component.name === 'QwikComponent') return false; const { html } = renderToStaticMarkup.call(this, Component, props, children); return typeof html === 'string'; }