From c58193a691775af5c568e461c63040a42e2471f7 Mon Sep 17 00:00:00 2001 From: Erika <3019731+Princesseuh@users.noreply.github.com> Date: Fri, 6 Sep 2024 11:38:15 +0200 Subject: [PATCH 1/3] fix(add): Use proper export names when adding adapters (#11935) * fix(add): Use proper export names when adding adapters * chore: changeset --- .changeset/green-bulldogs-shout.md | 5 +++++ packages/astro/src/cli/add/index.ts | 10 +++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 .changeset/green-bulldogs-shout.md diff --git a/.changeset/green-bulldogs-shout.md b/.changeset/green-bulldogs-shout.md new file mode 100644 index 000000000000..c58892b6c1a2 --- /dev/null +++ b/.changeset/green-bulldogs-shout.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fixes `astro add` not using the proper export point when adding certain adapters diff --git a/packages/astro/src/cli/add/index.ts b/packages/astro/src/cli/add/index.ts index f263904cbb4d..7866f5a093ab 100644 --- a/packages/astro/src/cli/add/index.ts +++ b/packages/astro/src/cli/add/index.ts @@ -279,7 +279,7 @@ export async function add(names: string[], { flags }: AddOptions) { if (isAdapter(integration)) { const officialExportName = OFFICIAL_ADAPTER_TO_IMPORT_MAP[integration.id]; if (officialExportName) { - setAdapter(mod, integration); + setAdapter(mod, integration, officialExportName); } else { logger.info( 'SKIP_FORMAT', @@ -447,7 +447,11 @@ function addIntegration(mod: ProxifiedModule, integration: IntegrationInfo) } } -export function setAdapter(mod: ProxifiedModule, adapter: IntegrationInfo) { +export function setAdapter( + mod: ProxifiedModule, + adapter: IntegrationInfo, + exportName: string, +) { const config = getDefaultExportOptions(mod); const adapterId = toIdent(adapter.id); @@ -455,7 +459,7 @@ export function setAdapter(mod: ProxifiedModule, adapter: IntegrationInfo) mod.imports.$append({ imported: 'default', local: adapterId, - from: adapter.packageName, + from: exportName, }); } From 4a44e82bbdf0572190618d8c5882c63a6525a198 Mon Sep 17 00:00:00 2001 From: Lukas Bachlechner <35543080+lukasbachlechner@users.noreply.github.com> Date: Fri, 6 Sep 2024 13:26:51 +0200 Subject: [PATCH 2/3] fix: explicitly check for null props in `serializeSignals` (#11930) * fix: explicitly check for null props in `serializeSignals` * chore: add changeset --- .changeset/long-lemons-add.md | 5 +++++ .../src/components/ComponentWithNullProp.jsx | 7 +++++++ .../test/fixtures/preact-component/src/pages/signals.astro | 4 +++- packages/astro/test/preact-component.test.js | 7 +++++++ packages/integrations/preact/src/signals.ts | 3 ++- 5 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 .changeset/long-lemons-add.md create mode 100644 packages/astro/test/fixtures/preact-component/src/components/ComponentWithNullProp.jsx diff --git a/.changeset/long-lemons-add.md b/.changeset/long-lemons-add.md new file mode 100644 index 000000000000..2ad0ecd20c9d --- /dev/null +++ b/.changeset/long-lemons-add.md @@ -0,0 +1,5 @@ +--- +'@astrojs/preact': patch +--- + +Preact components no longer throw an error if a property is null. diff --git a/packages/astro/test/fixtures/preact-component/src/components/ComponentWithNullProp.jsx b/packages/astro/test/fixtures/preact-component/src/components/ComponentWithNullProp.jsx new file mode 100644 index 000000000000..53856ce90275 --- /dev/null +++ b/packages/astro/test/fixtures/preact-component/src/components/ComponentWithNullProp.jsx @@ -0,0 +1,7 @@ +import { h } from 'preact'; + +export default ({ nullProp }) => { + return
+

I have a null prop: {nullProp}

+
+} \ No newline at end of file diff --git a/packages/astro/test/fixtures/preact-component/src/pages/signals.astro b/packages/astro/test/fixtures/preact-component/src/pages/signals.astro index 37b43a73c7ec..8abfe8f025db 100644 --- a/packages/astro/test/fixtures/preact-component/src/pages/signals.astro +++ b/packages/astro/test/fixtures/preact-component/src/pages/signals.astro @@ -3,6 +3,7 @@ import { signal } from '@preact/signals'; import Signals from '../components/Signals'; import SignalsInArray from '../components/SignalsInArray'; import SignalsInObject from '../components/SignalsInObject'; +import ComponentWithNullProp from '../components/ComponentWithNullProp'; const count = signal(1); const secondCount = signal(2); --- @@ -14,6 +15,7 @@ const secondCount = signal(2); - + + diff --git a/packages/astro/test/preact-component.test.js b/packages/astro/test/preact-component.test.js index f5b5c7233b1c..221245b1c334 100644 --- a/packages/astro/test/preact-component.test.js +++ b/packages/astro/test/preact-component.test.js @@ -140,4 +140,11 @@ describe('Preact component', () => { assert.equal(element.find('h1').text(), 'I am a title'); assert.equal(element.find('p').text(), '1'); }); + + it('Can use null props', async () => { + const html = await fixture.readFile('/signals/index.html'); + const $ = cheerio.load(html); + + assert.equal($('#preact-component-with-null-prop').length, 1); + }); }); diff --git a/packages/integrations/preact/src/signals.ts b/packages/integrations/preact/src/signals.ts index 7b797f3858f3..a1f63acdda75 100644 --- a/packages/integrations/preact/src/signals.ts +++ b/packages/integrations/preact/src/signals.ts @@ -38,7 +38,8 @@ export function serializeSignals( const signals: Signals = {}; for (const [key, value] of Object.entries(props)) { const isPropArray = Array.isArray(value); - const isPropObject = !isSignal(value) && typeof props[key] === 'object' && !isPropArray; + // `typeof null` is 'object' in JS, so we need to check for `null` specifically + const isPropObject = !isSignal(value) && typeof props[key] === 'object' && props[key] !== null && !isPropArray; if (isPropObject || isPropArray) { const values = isPropObject ? Object.keys(props[key]) : value; From 4a951597460aa11f4545e9452fe1afc004e5b51f Mon Sep 17 00:00:00 2001 From: Lukas Bachlechner Date: Fri, 6 Sep 2024 11:27:38 +0000 Subject: [PATCH 3/3] [ci] format --- packages/integrations/preact/src/signals.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/integrations/preact/src/signals.ts b/packages/integrations/preact/src/signals.ts index a1f63acdda75..88a50327a47f 100644 --- a/packages/integrations/preact/src/signals.ts +++ b/packages/integrations/preact/src/signals.ts @@ -39,7 +39,8 @@ export function serializeSignals( for (const [key, value] of Object.entries(props)) { const isPropArray = Array.isArray(value); // `typeof null` is 'object' in JS, so we need to check for `null` specifically - const isPropObject = !isSignal(value) && typeof props[key] === 'object' && props[key] !== null && !isPropArray; + const isPropObject = + !isSignal(value) && typeof props[key] === 'object' && props[key] !== null && !isPropArray; if (isPropObject || isPropArray) { const values = isPropObject ? Object.keys(props[key]) : value;