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

Support rendering @motionone/solid components #5233

Merged
merged 1 commit into from Oct 28, 2022
Merged

Conversation

bluwy
Copy link
Member

@bluwy bluwy commented Oct 28, 2022

Changes

Fix #4652

@motionone/solid components export a proxy component for Motion, so when you do Motion.div, it renders a div dynamically. The proxy captures the "div" (or anything) dynamically to render the right HTML element.

This brings many issues for Astro:

  1. await Motion returns undefined, because it's akin to Motion.then and there's no promise to resolve.
  2. Motion[Symbol.for('astro:renderer)] throws because the Proxy doesn't return the right value.
  3. Motion.isAstroComponentFactory is truthy because it returns a Solid component.

This PR handles these 3 edge cases to properly handle it. Another solution is to not have Motion wrap a Proxy, and follow styled-components' method of a hardcoded list of dom elements.

Testing

Added test to solid-component

Docs

N/A. bug fix.

@changeset-bot
Copy link

changeset-bot bot commented Oct 28, 2022

🦋 Changeset detected

Latest commit: 2bc94c8

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

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 Oct 28, 2022
Comment on lines +136 to +143
let isTagged = false;
try {
isTagged = Component && (Component as any)[Renderer];
} catch {
// Accessing `Component[Renderer]` may throw if `Component` is a Proxy that doesn't
// return the actual read-only value. In this case, ignore.
}
if (isTagged) {
Copy link
Member Author

Choose a reason for hiding this comment

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

The error would be something like:

 error   'get' on proxy: property 'Symbol(astro:renderer)' is a read-only and non-configurable data property on the proxy target but the proxy did not return its actual value (expected '@astrojs/solid-js' but got 'props => {
      delete props.tag;
      return __vite_ssr_import_1__.createComponent(BaseComponent, __vite_ssr_imp...<omitted>... }')

Copy link
Member Author

Choose a reason for hiding this comment

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

It would be very cheeky to parse the error message to get it's actual value now that I think of it, but right now it works without doing so.

Copy link
Contributor

@matthewp matthewp left a comment

Choose a reason for hiding this comment

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

seems like a wild one

@matthewp matthewp merged commit 7f89870 into main Oct 28, 2022
@matthewp matthewp deleted the support-motionone-solid branch October 28, 2022 14:42
@astrobot-houston astrobot-houston mentioned this pull request Oct 28, 2022
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.

Error when using solid.js packages: web.template is not a function
2 participants