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

Version 5.0.0-rc.0 #325

Merged
merged 20 commits into from
May 29, 2024
Merged

Version 5.0.0-rc.0 #325

merged 20 commits into from
May 29, 2024

Conversation

jamesrweb
Copy link
Collaborator

@jamesrweb jamesrweb commented Mar 2, 2024

Proposed Changes

  • Migrate to vitest 1.x.x, update tests and coverage reporting for this.
  • Utilize lazy component loading strategies to create smaller bundle sizes.
  • Move p5 to a peer dependency to allow users to install their preferred version while drastically reducing our bundle size even further in the process.
  • Implement an error boundary and expose ways for the consumer to handle error, loading and success cases if they want to. Provide simple defaults if they don't.
  • Brings test coverage up to effectively 100% when the it.skip tests are eventually unskipped, for now it is 98.x% covered which is much higher than previous versions, even with the it.skip cases.
  • Adds the React v19 compiler for development use

Additional Notes (optional)

This is a WIP and will probably take me some time to work through some ideas I have but this is the initial foundation of that process. That said, bundle size alone is massively reduced so far:

Version 4:

  • 1 MB minified
  • 237.8 KB minified + gzipped

Version 5 (latest update):

  • 6.24 KB minified (99.376% decrease)
  • 3.14 KB minified + gzipped (98.6796% decrease)

Migrate to vitest 1.x.x, update tests and coverage reporting for this. Utilize lazy component loading strategies to create smaller bundle sizes. Move p5 to a peer dependency to allow users to install their preferred version while drastically reducing our bundle size even further in the process.
@jamesrweb jamesrweb added enhancement dependencies Pull requests that update a dependency file security This label applies to security issues documentation Pull requests that update project documentation labels Mar 2, 2024
@jamesrweb jamesrweb requested a review from yevdyko March 2, 2024 03:44
@jamesrweb jamesrweb self-assigned this Mar 2, 2024
Update test structure and coverage to match that of src files. Allow for error, loading and fallback views. Add test coverage for the new view types, constants and utils. Merge previous tests into a single file since these all test the same component in the end. Update configs for eslint to handle more hooks cases. Disallow logs in test output since these are distracting and not necessary at this time.
@jamesrweb
Copy link
Collaborator Author

@yevdyko this is basically ready to go pending your review but I want to leave it as a draft since the README will need updated still and maybe you or I have other ideas to add to this foundation. I won't push more changes until you review the current state, thanks in advance! 🚀

@yevdyko yevdyko mentioned this pull request Mar 3, 2024
Copy link
Collaborator

@yevdyko yevdyko left a comment

Choose a reason for hiding this comment

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

Thanks @jamesrweb! This looks like really good improvements. Much appreciate your efforts 🥇

Since this will be the new major version, maybe we can rename the main component. For example, from ReactP5Wrapper to P5Canvas. The idea is that we can be more particular in naming and specify what it is instead of just declaring that we wrap p5 in a component using React, which is obvious if you're building a React application. WDYT @jamesrweb ?

demo/app.jsx Show resolved Hide resolved
@jamesrweb jamesrweb requested a review from yevdyko May 3, 2024 16:09
@jamesrweb
Copy link
Collaborator Author

Thanks @jamesrweb! This looks like really good improvements. Much appreciate your efforts 🥇

Since this will be the new major version, maybe we can rename the main component. For example, from ReactP5Wrapper to P5Canvas. The idea is that we can be more particular in naming and specify what it is instead of just declaring that we wrap p5 in a component using React, which is obvious if you're building a React application. WDYT @jamesrweb ?

I don't know, the component has been named this for 2 major versions if I am not mistaken and I think it is a "recognised" marker of the project. I don't know, I will think about it though!

@jamesrweb
Copy link
Collaborator Author

@yevdyko version 5 is basically ready now, please review and check the tests, documentation and see if I missed anything please! ❤️

@jamesrweb jamesrweb marked this pull request as ready for review May 3, 2024 16:14
@yevdyko
Copy link
Collaborator

yevdyko commented May 3, 2024

@jamesrweb Thanks for the updates. I'll try to review the changes over the weekend

Copy link
Collaborator

@yevdyko yevdyko left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

Thanks for the new features and improving test coverage 💪

.gitignore Outdated
@@ -26,3 +26,4 @@ pnpm-lock.yaml
*.njsproj
*.sln
*.sw?
tsconfig.tsbuildinfo
Copy link
Collaborator

Choose a reason for hiding this comment

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

MINOR:

It would be nice to add a new line to the end of the file

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Pushed with a new line, mind if I ask why though? 😛

Copy link
Collaborator Author

@jamesrweb jamesrweb May 6, 2024

Choose a reason for hiding this comment

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

Did you manage to test version 5 with any sketches of your own or any others? I would appreciate the feedback if you did, I tried with some of mine but simple use cases only so far.

Copy link
Collaborator

Choose a reason for hiding this comment

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

As for the new line, it's specific to git, how the diff utility is implemented. That's why github highlighted it. Read more: https://unix.stackexchange.com/a/18744

We can add an editorconfig file to the repository to avoid this in the future: https://editorconfig.org/#example-file

Copy link
Collaborator

Choose a reason for hiding this comment

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

I haven't tested it locally, but I may do so today / tomorrow

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Okay, I'll wait for you to test and give feedback then before merging.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think editorconfig is good but prettier would be better, maybe we can automate that somehow, a custom rule or simple plugin for example.

@jamesrweb jamesrweb requested a review from yevdyko May 10, 2024 13:50
@yevdyko
Copy link
Collaborator

yevdyko commented May 14, 2024

@jamesrweb I tried to test the latest changes in my demo app and ran into the issue when importing the component:

Compiled with problems:
×
ERROR in ./src/App.js 28:30-44
export 'ReactP5Wrapper' (imported as 'ReactP5Wrapper') was not found in '@p5-wrapper/react' (module has no exports)

I installed the new version of the package from git and built it inside node_modules, so maybe there is something wrong with the changes themselves or I'm not importing it correctly. So I'll try to figure out what's wrong in my case again tomorrow, but maybe you have some ideas.

@jamesrweb
Copy link
Collaborator Author

@jamesrweb I tried to test the latest changes in my demo app and ran into the issue when importing the component:

Compiled with problems:
×
ERROR in ./src/App.js 28:30-44
export 'ReactP5Wrapper' (imported as 'ReactP5Wrapper') was not found in '@p5-wrapper/react' (module has no exports)

I installed the new version of the package from git and built it inside node_modules, so maybe there is something wrong with the changes themselves or I'm not importing it correctly. So I'll try to figure out what's wrong in my case again tomorrow, but maybe you have some ideas.

Screenshot 2024-05-15 at 13 43 49

It definitely builds it into the export list as shown in the image above. I wonder if you need to re-install your dependencies or something because the package.json values for main, module and exports changed in version 5 as shown here:

Screenshot 2024-05-15 at 13 45 02

Also we have more files in the library due to the Suspense and lazy boundaries for lazy loading components on demand, etc, as shown here:

Screenshot 2024-05-15 at 13 44 34

@yevdyko
Copy link
Collaborator

yevdyko commented May 15, 2024

@jamesrweb I have updated all dependencies and cleaned up all modules before installing the new version. Have you tried using the new version in a standalone React app rather than a demo where the component is used directly from a folder nearby rather than the build?

@jamesrweb
Copy link
Collaborator Author

jamesrweb commented May 15, 2024

@jamesrweb I have updated all dependencies and cleaned up all modules before installing the new version. Have you tried using the new version in a standalone React app rather than a demo where the component is used directly from a folder nearby rather than the build?

The CJS version was overwriting main.js (since both used the same file name 😅), I fixed the builder and retested the demo and it works with the es version imported now. Please try again 😄

@yevdyko
Copy link
Collaborator

yevdyko commented May 15, 2024

@jamesrweb Yeah, that solved the import issue. Thanks for the fix!

There are a few runtime errors related to the package and possibly to the changes:

image

@jamesrweb
Copy link
Collaborator Author

@jamesrweb Yeah, that solved the import issue. Thanks for the fix!

There are a few runtime errors related to the package and possibly to the changes:

image

I don't get this in the demo app for any of the sketches 🤔... you're sure that react, react-dom and p5 (since they're peer deps) are installed in your project?

The only refs being used in that file are to the canvas instance and the wrapper div. The null cases are handled in the effects and the refs mount the values when the component renders.

Not sure why this could be...

  • What's your repo / setup like? Can you share?
  • Is it in next or raw react?
  • Did you check the DOM to see the render tree is correct?

@yevdyko
Copy link
Collaborator

yevdyko commented May 16, 2024

I don't get this in the demo app for any of the sketches 🤔... you're sure that react, react-dom and p5 (since they're peer deps) are installed in your project?

The only refs being used in that file are to the canvas instance and the wrapper div. The null cases are handled in the effects and the refs mount the values when the component renders.

Not sure why this could be...

  • What's your repo / setup like? Can you share?
  • Is it in next or raw react?
  • Did you check the DOM to see the render tree is correct?

@jamesrweb The dependencies are installed correctly. This is most likely due to your changes related to lazy loading. Unfortunately, this will not be reproducible in the demo from the package repository, as it does not use the built version of the package. Here is the repo with my test React app: https://github.com/yevdyko/react-p5-wrapper-demo/tree/test-version-5

Could you check this using my demo app or create your own with the latest version of the package installed in it?

@jamesrweb
Copy link
Collaborator Author

jamesrweb commented May 16, 2024

I don't get this in the demo app for any of the sketches 🤔... you're sure that react, react-dom and p5 (since they're peer deps) are installed in your project?

The only refs being used in that file are to the canvas instance and the wrapper div. The null cases are handled in the effects and the refs mount the values when the component renders.

Not sure why this could be...

  • What's your repo / setup like? Can you share?
  • Is it in next or raw react?
  • Did you check the DOM to see the render tree is correct?

@jamesrweb The dependencies are installed correctly. This is most likely due to your changes related to lazy loading. Unfortunately, this will not be reproducible in the demo from the package repository, as it does not use the built version of the package. Here is the repo with my test React app: https://github.com/yevdyko/react-p5-wrapper-demo/tree/test-version-5

Could you check this using my demo app or create your own with the latest version of the package installed in it?

I did use the built script from the demo by manually changing the path to use the script from dist and it was fine. 🤷🏻‍♂️

Note: I accidentally edited your comment earlier instead of replying, no idea how that happened but sorry 😂😂

@jamesrweb
Copy link
Collaborator Author

@yevdyko I just added the react v19 compiler for development into this version, to ensure we are adhering to the rules of hooks, rules of react and are prepared for the upcoming version 19 changes.

}))
);

export default function ReactP5WrapperGuard<Props extends SketchProps>(
Copy link
Collaborator

Choose a reason for hiding this comment

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

@jamesrweb I have reinstalled the packages in my demo application. There seems to be some runtime errors related to the changes in ReactP5WrapperGuard:

image

Copy link
Collaborator Author

@jamesrweb jamesrweb May 26, 2024

Choose a reason for hiding this comment

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

Try installing react@beta and react-dom@beta and let me know if it works then? If it does I might need to decide to either:

  • A: drop react 19 support in the build
  • B: only support react 19+ for version 5

React 19 is just round the corner so this might not be such a bad thing and from my own testing, yes it's beta in the meantime but it's very stable so far in other projects of mine so I'd be okay with that, WDYT? 🤷🏻‍♂️

Copy link
Collaborator

Choose a reason for hiding this comment

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

@jamesrweb After installing react@beta, there are still runtime errors related to useRef:

image

I assume this is not related to changes in react 19 support, but it may be relevant to the ReactP5WrapperGuard component as I mentioned above.

It would be nice if you tested your branch with an external React app, otherwise you can release as is, but there is a good chance the package won't work I think. So it's up to you.

@jamesrweb jamesrweb changed the title Version 5 Version 5.0.0-rc.0 May 29, 2024
@jamesrweb jamesrweb merged commit dd67d2b into master May 29, 2024
8 checks passed
@jamesrweb jamesrweb deleted the version-5 branch May 29, 2024 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file documentation Pull requests that update project documentation enhancement security This label applies to security issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants