From 72b26daf694b213918f02d0fcbf90ab5b7ebc31f Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Wed, 20 Dec 2023 12:59:49 -0600 Subject: [PATCH 1/4] Skip `check` for known Qwik components (#9482) --- .changeset/eight-ears-call.md | 7 +++++++ packages/integrations/preact/src/server.ts | 1 + packages/integrations/react/server-v17.js | 1 + packages/integrations/react/server.js | 1 + packages/integrations/solid/src/server.ts | 1 + 5 files changed, 11 insertions(+) create mode 100644 .changeset/eight-ears-call.md 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/packages/integrations/preact/src/server.ts b/packages/integrations/preact/src/server.ts index a395433c9bad..1de6d174f4c0 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..12e1f198e4f1 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..810c37250fcc 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..eb73f0af18e3 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'; } From 60dc8da71b40fb080cd77a01ba39c92b7bbef423 Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Wed, 20 Dec 2023 19:00:58 +0000 Subject: [PATCH 2/4] [ci] format --- packages/integrations/preact/src/server.ts | 2 +- packages/integrations/react/server-v17.js | 2 +- packages/integrations/react/server.js | 2 +- packages/integrations/solid/src/server.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/integrations/preact/src/server.ts b/packages/integrations/preact/src/server.ts index 1de6d174f4c0..7d017a413951 100644 --- a/packages/integrations/preact/src/server.ts +++ b/packages/integrations/preact/src/server.ts @@ -13,7 +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.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 12e1f198e4f1..ad0c99622b56 100644 --- a/packages/integrations/react/server-v17.js +++ b/packages/integrations/react/server-v17.js @@ -20,7 +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.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 810c37250fcc..b3ddeb6b1d12 100644 --- a/packages/integrations/react/server.js +++ b/packages/integrations/react/server.js @@ -22,7 +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; + 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 eb73f0af18e3..445e4605e9de 100644 --- a/packages/integrations/solid/src/server.ts +++ b/packages/integrations/solid/src/server.ts @@ -6,7 +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; + if (Component.name === 'QwikComponent') return false; const { html } = renderToStaticMarkup.call(this, Component, props, children); return typeof html === 'string'; } From dfef925e1fd07f3efb9fde6f4f23548f2af7dc75 Mon Sep 17 00:00:00 2001 From: Arsh <69170106+lilnasy@users.noreply.github.com> Date: Wed, 20 Dec 2023 21:13:50 +0000 Subject: [PATCH 3/4] chore: improve type fidelity for internal error class (#9478) * chore: improve type fidelity for internal error class * add changeset * simplify * fix: adjust for new error --------- Co-authored-by: Princesseuh <3019731+Princesseuh@users.noreply.github.com> --- .changeset/rare-ants-swim.md | 5 +++++ packages/astro/src/assets/build/generate.ts | 1 - packages/astro/src/core/errors/errors.ts | 14 +++++++------- .../astro/src/core/middleware/loadMiddleware.ts | 2 +- 4 files changed, 13 insertions(+), 9 deletions(-) create mode 100644 .changeset/rare-ants-swim.md 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..31e3be52026c 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; } } From f9c4bbf200820915f5526fcd8d5c399c51b44f71 Mon Sep 17 00:00:00 2001 From: Arsh Date: Wed, 20 Dec 2023 21:15:00 +0000 Subject: [PATCH 4/4] [ci] format --- packages/astro/src/core/errors/errors.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/astro/src/core/errors/errors.ts b/packages/astro/src/core/errors/errors.ts index 31e3be52026c..37373527b03d 100644 --- a/packages/astro/src/core/errors/errors.ts +++ b/packages/astro/src/core/errors/errors.ts @@ -41,7 +41,7 @@ export class AstroError extends Error { constructor(props: ErrorProperties, options?: ErrorOptions) { const { name, title, message, stack, location, hint, frame } = props; super(message, options); - + this.title = title; this.name = name;