Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: exportName metadata for JSXMemberExpressions that use named imports #4403

Merged

Conversation

JohnDaly
Copy link
Contributor

@JohnDaly JohnDaly commented Aug 21, 2022

Changes

Fix for issue described in: #4389

Components declared using JSXMemberExpression nodes were not hydrating properly, due to how the component-export attribute was being determined in the astroJSX Babel plugin.

Example:

const SampleComponent = () => { ... }

export const Namespace = { SampleComponent };

The component-export attribute for this component (<Namespace.SampleComponent client:load />) was 'SampleComponent', but will now be 'Namespace.SampleComponent', which can be resolved properly via the hydration logic here:

this.Component = componentModule;
for (const part of componentExport.split('.')) {
this.Component = this.Component[part]
}

Testing

Tested locally. I also added to the existing e2e/namespaced-component.test.js.

Docs

No documentation updates needed. This is a minor bug fix.

@changeset-bot
Copy link

changeset-bot bot commented Aug 21, 2022

🦋 Changeset detected

Latest commit: ae9f82f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
astro Patch
@e2e/astro-component Patch
@e2e/error-react-spectrum Patch
@e2e/error-sass Patch
@e2e/errors Patch
@e2e/lit-component Patch
@e2e/preact-component Patch
@e2e/react-component Patch
@e2e/solid-component Patch
@e2e/solid-recurse Patch
@e2e/svelte-component Patch
@e2e/e2e-tailwindcss Patch
@e2e/ts-resolution Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Aug 21, 2022
@@ -205,7 +205,8 @@ export default function astroJSX(): PluginObj {
break;
}
if (namespace.at(0) === local) {
path.setData('import', { name: imported, path: source });
const name = imported === '*' ? imported : tagName;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Components that use an ImportNamespaceSpecifier will have their import name set to '*', which is handled here:

if (meta.name === '*') {
meta.name = getTagName(node).split('.').slice(1).join('.')!;
}

In other cases, we'll just use the tag name, which will be resolved in the same way that the namespace is. That happens here:

this.Component = componentModule;
for (const part of componentExport.split('.')) {
this.Component = this.Component[part]
}

@matthewp
Copy link
Contributor

Note that @natemoo-re is going to work on this issue.

Copy link
Member

@natemoo-re natemoo-re left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix, looks great!

@natemoo-re natemoo-re merged commit d31e72c into withastro:main Sep 7, 2022
@astrobot-houston astrobot-houston mentioned this pull request Sep 7, 2022
@JohnDaly JohnDaly deleted the fix/jsx-member-expression-transform branch September 17, 2022 23:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants