fix: exportName metadata for JSXMemberExpressions that use named imports (#4403)
* fix: exportName metadata for JSXMemberExpressions that use named imports * Adding changeset * Adding E2E test * Adding tests for MDX
This commit is contained in:
parent
c01194b9d8
commit
d31e72c3ba
8 changed files with 88 additions and 13 deletions
5
.changeset/soft-icons-travel.md
Normal file
5
.changeset/soft-icons-travel.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix for components, declared with JSXMemberExpression nodes, that failed to hydrate due to incomplete 'component-export' metadata
|
|
@ -1,7 +1,8 @@
|
||||||
import { defineConfig } from 'astro/config';
|
import { defineConfig } from 'astro/config';
|
||||||
import preact from '@astrojs/preact';
|
import preact from '@astrojs/preact';
|
||||||
|
import mdx from "@astrojs/mdx";
|
||||||
|
|
||||||
// https://astro.build/config
|
// https://astro.build/config
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
integrations: [preact()],
|
integrations: [preact(), mdx()]
|
||||||
});
|
});
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@astrojs/mdx": "workspace:*",
|
||||||
"@astrojs/preact": "workspace:*",
|
"@astrojs/preact": "workspace:*",
|
||||||
"astro": "workspace:*"
|
"astro": "workspace:*"
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
---
|
---
|
||||||
import * as ns from '../components/PreactCounter.tsx';
|
import * as ns from '../components/PreactCounter.tsx';
|
||||||
|
import { components } from '../components/PreactCounter.tsx';
|
||||||
---
|
---
|
||||||
|
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
@ -10,9 +11,13 @@ import * as ns from '../components/PreactCounter.tsx';
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<main>
|
<main>
|
||||||
<ns.components.PreactCounter id="preact-counter" client:load>
|
<ns.components.PreactCounter id="preact-counter-namespace" client:load>
|
||||||
<h1>preact</h1>
|
<h1>preact (namespace import)</h1>
|
||||||
</ns.components.PreactCounter>
|
</ns.components.PreactCounter>
|
||||||
|
|
||||||
|
<components.PreactCounter id="preact-counter-named" client:load>
|
||||||
|
<h1>preact (named import)</h1>
|
||||||
|
</components.PreactCounter>
|
||||||
</main>
|
</main>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
import * as ns from '../components/PreactCounter.tsx';
|
||||||
|
import { components } from '../components/PreactCounter.tsx';
|
||||||
|
|
||||||
|
<ns.components.PreactCounter id="preact-counter-namespace" client:load>
|
||||||
|
preact (namespace import)
|
||||||
|
</ns.components.PreactCounter>
|
||||||
|
|
||||||
|
<components.PreactCounter id="preact-counter-named" client:load>
|
||||||
|
preact (named import)
|
||||||
|
</components.PreactCounter>
|
|
@ -19,18 +19,68 @@ test.describe('Hydrating namespaced components', () => {
|
||||||
test('Preact Component', async ({ page }) => {
|
test('Preact Component', async ({ page }) => {
|
||||||
await page.goto('/');
|
await page.goto('/');
|
||||||
|
|
||||||
const counter = await page.locator('#preact-counter');
|
// Counter declared with: <ns.components.PreactCounter id="preact-counter-namespace" client:load>
|
||||||
await expect(counter, 'component is visible').toBeVisible();
|
const namespacedCounter = await page.locator('#preact-counter-namespace');
|
||||||
|
await expect(namespacedCounter, 'component is visible').toBeVisible();
|
||||||
|
|
||||||
const count = await counter.locator('pre');
|
const namespacedCount = await namespacedCounter.locator('pre');
|
||||||
await expect(count, 'initial count is 0').toHaveText('0');
|
await expect(namespacedCount, 'initial count is 0').toHaveText('0');
|
||||||
|
|
||||||
const children = await counter.locator('.children');
|
const namespacedChildren = await namespacedCounter.locator('.children');
|
||||||
await expect(children, 'children exist').toHaveText('preact');
|
await expect(namespacedChildren, 'children exist').toHaveText('preact (namespace import)');
|
||||||
|
|
||||||
const increment = await counter.locator('.increment');
|
const namespacedIncrement = await namespacedCounter.locator('.increment');
|
||||||
await increment.click();
|
await namespacedIncrement.click();
|
||||||
|
|
||||||
await expect(count, 'count incremented by 1').toHaveText('1');
|
await expect(namespacedCount, 'count incremented by 1').toHaveText('1');
|
||||||
|
|
||||||
|
// Counter declared with: <components.PreactCounterTwo id="preact-counter-named" client:load>
|
||||||
|
const namedCounter = await page.locator('#preact-counter-named');
|
||||||
|
await expect(namedCounter, 'component is visible').toBeVisible();
|
||||||
|
|
||||||
|
const namedCount = await namedCounter.locator('pre');
|
||||||
|
await expect(namedCount, 'initial count is 0').toHaveText('0');
|
||||||
|
|
||||||
|
const namedChildren = await namedCounter.locator('.children');
|
||||||
|
await expect(namedChildren, 'children exist').toHaveText('preact (named import)');
|
||||||
|
|
||||||
|
const namedIncrement = await namedCounter.locator('.increment');
|
||||||
|
await namedIncrement.click();
|
||||||
|
|
||||||
|
await expect(namedCount, 'count incremented by 1').toHaveText('1');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('MDX', async ({ page }) => {
|
||||||
|
await page.goto('/mdx');
|
||||||
|
|
||||||
|
// Counter declared with: <ns.components.PreactCounter id="preact-counter-namespace" client:load>
|
||||||
|
const namespacedCounter = await page.locator('#preact-counter-namespace');
|
||||||
|
await expect(namespacedCounter, 'component is visible').toBeVisible();
|
||||||
|
|
||||||
|
const namespacedCount = await namespacedCounter.locator('pre');
|
||||||
|
await expect(namespacedCount, 'initial count is 0').toHaveText('0');
|
||||||
|
|
||||||
|
const namespacedChildren = await namespacedCounter.locator('.children');
|
||||||
|
await expect(namespacedChildren, 'children exist').toHaveText('preact (namespace import)');
|
||||||
|
|
||||||
|
const namespacedIncrement = await namespacedCounter.locator('.increment');
|
||||||
|
await namespacedIncrement.click();
|
||||||
|
|
||||||
|
await expect(namespacedCount, 'count incremented by 1').toHaveText('1');
|
||||||
|
|
||||||
|
// Counter declared with: <components.PreactCounterTwo id="preact-counter-named" client:load>
|
||||||
|
const namedCounter = await page.locator('#preact-counter-named');
|
||||||
|
await expect(namedCounter, 'component is visible').toBeVisible();
|
||||||
|
|
||||||
|
const namedCount = await namedCounter.locator('pre');
|
||||||
|
await expect(namedCount, 'initial count is 0').toHaveText('0');
|
||||||
|
|
||||||
|
const namedChildren = await namedCounter.locator('.children');
|
||||||
|
await expect(namedChildren, 'children exist').toHaveText('preact (named import)');
|
||||||
|
|
||||||
|
const namedIncrement = await namedCounter.locator('.increment');
|
||||||
|
await namedIncrement.click();
|
||||||
|
|
||||||
|
await expect(namedCount, 'count incremented by 1').toHaveText('1');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -207,7 +207,8 @@ export default function astroJSX(): PluginObj {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (namespace.at(0) === local) {
|
if (namespace.at(0) === local) {
|
||||||
path.setData('import', { name: imported, path: source });
|
const name = imported === '*' ? imported : tagName;
|
||||||
|
path.setData('import', { name, path: source });
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
2
pnpm-lock.yaml
generated
2
pnpm-lock.yaml
generated
|
@ -698,12 +698,14 @@ importers:
|
||||||
|
|
||||||
packages/astro/e2e/fixtures/namespaced-component:
|
packages/astro/e2e/fixtures/namespaced-component:
|
||||||
specifiers:
|
specifiers:
|
||||||
|
'@astrojs/mdx': workspace:*
|
||||||
'@astrojs/preact': workspace:*
|
'@astrojs/preact': workspace:*
|
||||||
astro: workspace:*
|
astro: workspace:*
|
||||||
preact: ^10.7.3
|
preact: ^10.7.3
|
||||||
dependencies:
|
dependencies:
|
||||||
preact: 10.10.6
|
preact: 10.10.6
|
||||||
devDependencies:
|
devDependencies:
|
||||||
|
'@astrojs/mdx': link:../../../../integrations/mdx
|
||||||
'@astrojs/preact': link:../../../../integrations/preact
|
'@astrojs/preact': link:../../../../integrations/preact
|
||||||
astro: link:../../..
|
astro: link:../../..
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue