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

feat(react-output-target): generate functional components and ES modules #432

Merged
merged 23 commits into from
May 30, 2024

Conversation

sean-perkins
Copy link
Contributor

@sean-perkins sean-perkins commented Apr 30, 2024

Pull request checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)
  • Build (npm run build) was run locally for affected output targets
  • Tests (npm test) were run locally and passed
  • Prettier (npm run prettier) was run locally and passed

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

What is the current behavior?

Issue URL: resolves #255, #89, #404, closes #361, #243, #198, #88, #359, #148, #138

The issues linked are either resolved from these changes or no longer apply due to these changes. I've tried to separate them as such to help future maintainers separate why so many tickets are attached to this PR.

What is the new behavior?

React Output Target

  • Rewrites the react output target to standardize around the custom elements output target
  • Adds support for generating separate ES modules for each component
  • Component wrappers are generated as functional components
  • Experimental option to generate component wrappers with use client; directive.
  • Adds wdio tests for the test application

Does this introduce a breaking change?

  • Yes
  • No

Other information

Latest dev-build (2024-05-22): 0.0.1-dev.11716386285.1a6265fd

@sean-perkins sean-perkins mentioned this pull request Apr 30, 2024
14 tasks
@sean-perkins sean-perkins marked this pull request as ready for review May 15, 2024 13:49
@sean-perkins sean-perkins requested review from a team as code owners May 15, 2024 13:49
@sean-perkins sean-perkins requested review from alicewriteswrongs, tanner-reits and thetaPC and removed request for a team May 15, 2024 13:49
Copy link
Member

@christian-bromann christian-bromann left a comment

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

@tanner-reits tanner-reits left a comment

Choose a reason for hiding this comment

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

Overall, looking good. Noticed a couple things:

  1. The runtime entry-point isn't a valid import location in some instances. This is an issue with the React library's tsconfig.json values. Setting module to Preserve and moduleResolution to Bundler resolves it. Need to determine if there are any breaking changes or downstream issues for projects that need to make this change.
  2. Output is not cleared between builds. This can cause issues with non-existent components being left in the output directory when using esModules.

@sean-perkins
Copy link
Contributor Author

I looked into 1. The use of imports and exports in the package.json requires a feature available in TypeScript 5, moduleResolution: "bundler". When enabled, this also requires module: "esnext" to be configured. I will make sure these details are included in both the repository README and update the documentation updates as I don't think it will be commonly known by developers.

Reflecting more on our conversation with 2, I am less confident if we should clear the directory or files. The goal is to co-locate your generated component wrappers alongside any potential React-only components/component implementations. Clearing the directory between builds would prevent this. If we wanted to do this is a less destructive way, we would need to keep a generated output of what the react-output-target generated somewhere and parse that to determine what files are "owned" by the output target and are safe to delete between builds. This could be a cool feature, but I would recommend we track that as follow-up scope.

When testing I also observed the new output no longer uses the syntax sugar for bundlers like webpack for marking functions as pure. I will see what the work effort to generate this through ts-morph is.

@tanner-reits
Copy link
Contributor

I think that's fine. We're making a similar concession in Stencil for generating export maps. Hard to know what was user-generated and auto-generated and what changed between builds.

@sean-perkins
Copy link
Contributor Author

We received some feedback from testing, there is two different underlying issues with more complex type usages on custom events. I am going to try reproducing locally and update the output target to account for those.

It is possible for it to use a reference as value instead of typeof and it does not import all type references used. The demo code provides includes the use of nested namespaces.

@sean-perkins
Copy link
Contributor Author

Identified the issues with the PR. I was incorrectly using the resolved (inline) type instead of directly leveraging the original type references that Stencil re-exports and specifies on the events metadata. This ended up resolving both issues.

@sean-perkins sean-perkins requested a review from tanner-reits May 22, 2024 13:59
Copy link
Contributor

@tanner-reits tanner-reits left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Contributor

@thetaPC thetaPC left a comment

Choose a reason for hiding this comment

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

LGTM, tested on Ionic Framework and Stencil DS Output Targets.

@sean-perkins sean-perkins merged commit ff3f2df into next May 30, 2024
5 checks passed
@sean-perkins sean-perkins deleted the sp/react-output-target branch May 30, 2024 17:02
sean-perkins added a commit that referenced this pull request Aug 13, 2024
…les (#432)

* feat: migrate to lit/react component wrappers
christian-bromann pushed a commit that referenced this pull request Aug 20, 2024
…les (#432)

* feat: migrate to lit/react component wrappers
christian-bromann pushed a commit that referenced this pull request Aug 26, 2024
…les (#432)

* feat: migrate to lit/react component wrappers
christian-bromann added a commit that referenced this pull request Aug 27, 2024
* feat(react-output-target): generate functional components and ES modules (#432)

* feat: migrate to lit/react component wrappers

* exploration nextjs support

* update Stencil with support for DSD

* get rid of hydration errors

* enhance output target

* add tests

* fix dep

* remove type property in package.json

* remove hydrate dir

* move ssr support into custom export

* clear hydrate folder again

* skip lib check

* skip lib check

* better resolve light dom

* remove unused import

* match default dir with stencil

* more improvements on light dom rendering

* remove duplicate hydrate ot

* remove style prop

* fail if outdir is not set

* import hydration script and ssr runtime only within the server component

* validate hydrate output target to be set if hydrateModule option is set

* improve implementation

* separate files for server and client components

* properly create server and client side components

* don't parse children

* use own runtime

* validate that external runtime is set to 'true'

* adjust test

* update Stencil dev build

* recognise that externalRuntime default is true

* bring back light DOM rendering for better hydration results

* revert light dom approach

* minor formatting

* update stencil

* explicitly type component exports

* unit test tweak

* fix build

* use latest Stencil release

* fix test

---------

Co-authored-by: Sean Perkins <[email protected]>
@TRMW
Copy link

TRMW commented Sep 17, 2024

I looked into 1. The use of imports and exports in the package.json requires a feature available in TypeScript 5, moduleResolution: "bundler". When enabled, this also requires module: "esnext" to be configured. I will make sure these details are included in both the repository README and update the documentation updates as I don't think it will be commonly known by developers.

I just ran into this issue trying to update to the latest version of this package. Would be great to document this in the README. :)

@sean-perkins
Copy link
Contributor Author

@TRMW
Copy link

TRMW commented Sep 17, 2024

@sean-perkins I just realized this! Thanks for the help though!

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.

5 participants