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

Improved JSX framework detection #382

Merged
merged 2 commits into from
Jun 14, 2021
Merged

Improved JSX framework detection #382

merged 2 commits into from
Jun 14, 2021

Conversation

matthewp
Copy link
Contributor

Changes

This improves the JSX detection and adds a bunch of test. The following is improved:

  • If an error throws because of a coding mistake, those errors will be reported.
  • We properly detect class components for both Preact and React. We don't have to "try to render" these.

It's still possible that error messages might be obscured in this scenario:

A Preact function component that uses hooks (or another preact specific feature) that has a coding mistake. The React renderer might throw when it uses the Preact hook. That error will be reported rather than the real coding mistake.

This is because we can't distinguish between errors that are due to the wrong framework and errors that the user caused.

I might reach out to the Preact community and see if they can think of a better solution to this problem. This will come up when other JSX based frameworks have renderers. I still think that having multiple frameworks in the same project is a feature worth trying to preserve.

Testing

  • [✅] Tests are passing
  • [✅] Tests updated where necessary

Docs

N/A

This improves the JSX detection and adds a bunch of test. The following is improved:

* If an error throws because of a coding mistake, those errors will be reported.
* We properly detect class components for both Preact and React. We don't have to "try to render" these.

It's still possible that error messages might be obscured in this scenario:

A Preact function component that uses hooks (or another preact specific feature) that has a coding mistake. The React renderer might throw when it uses the Preact hook. That error will be reported rather than the real coding mistake.

This is because we can't distinguish between errors that are due to the wrong framework and errors that the user caused.

I might reach out to the Preact community and see if they can think of a better solution to this problem. This will come up when other JSX based frameworks have renderers. I still think that having multiple frameworks in the same project is a feature worth trying to preserve.
@matthewp matthewp requested a review from a team as a code owner June 11, 2021 16:28
@vercel
Copy link

vercel bot commented Jun 11, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/pikapkg/astro-www/Hkb3foCHdsCNpWcTa3vR1LyJM6J5
✅ Preview: https://astro-www-git-better-jsx-detection-pikapkg.vercel.app

@changeset-bot
Copy link

changeset-bot bot commented Jun 11, 2021

⚠️ No Changeset found

Latest commit: 2818354

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

Copy link
Member

@drwpow drwpow left a comment

Choose a reason for hiding this comment

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

🎉

@drwpow
Copy link
Member

drwpow commented Jun 11, 2021

I still think that having multiple frameworks in the same project is a feature worth trying to preserve.

+100 to this. And I think Preact and React are very likely cohabitants of the same project, especially if someone is trying to migrate from React to Preact, for example.

@FredKSchott
Copy link
Member

+1 as well. I still want to have a convo about the best way to deliver on that though. (Maybe .react.jsx, maybe a /// astro.renderer=react at the top of the file, etc. etc.) but this is a great step forward regardless

@matthewp
Copy link
Contributor Author

Realized I can probably move the try/catch out of the renderer, simplifying it's signature. So I want to make that change before merging this.

@matthewp matthewp merged commit 271cfe6 into main Jun 14, 2021
@matthewp matthewp deleted the better-jsx-detection branch June 14, 2021 12:35
SiriousHunter pushed a commit to SiriousHunter/astro that referenced this pull request Feb 3, 2023
* Improved JSX framework detection

This improves the JSX detection and adds a bunch of test. The following is improved:

* If an error throws because of a coding mistake, those errors will be reported.
* We properly detect class components for both Preact and React. We don't have to "try to render" these.

It's still possible that error messages might be obscured in this scenario:

A Preact function component that uses hooks (or another preact specific feature) that has a coding mistake. The React renderer might throw when it uses the Preact hook. That error will be reported rather than the real coding mistake.

This is because we can't distinguish between errors that are due to the wrong framework and errors that the user caused.

I might reach out to the Preact community and see if they can think of a better solution to this problem. This will come up when other JSX based frameworks have renderers. I still think that having multiple frameworks in the same project is a feature worth trying to preserve.

* Move try/catch into the __astro_component
ematipico pushed a commit that referenced this pull request Feb 5, 2025
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
ematipico pushed a commit that referenced this pull request Feb 5, 2025
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
ematipico pushed a commit that referenced this pull request Feb 6, 2025
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
ematipico pushed a commit that referenced this pull request Feb 6, 2025
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
ematipico pushed a commit that referenced this pull request Feb 7, 2025
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants