preactjs / preact

⚛️ Fast 3kB React alternative with the same modern API. Components & Virtual DOM.
https://preactjs.com
MIT License
36.72k stars 1.95k forks source link

Preact build without Component classes and related code #2145

Open Rafi993 opened 4 years ago

Rafi993 commented 4 years ago

It would be awesome if there is a Preact build that removes Component class and related code from it and just has support for hooks alone. So that build size is further reduced for code that will only be using hooks alone instead of class related components. Is there any plans on this ?

marvinhagemeister commented 4 years ago

This idea has come up a few times since hooks were unveiled. The problem is that there are tons of third party libraries out there which depend on the class-API. Removing it from Preact would break a huge chunk of our ecosystem. It's an idea we keep in mind, but can't execute on right now.

Rafi993 commented 4 years ago

That is true. I am not talking about removing it from the repo but creating separate build (using some script ) in addition to the default build for people who want to use it and with warning that it may not work third party libraries that use components.

Rafi993 commented 4 years ago

It will provide users with option to use hooks only build instead of default build for specific use cases where there is no external react libraries used (or using only libraries that are hooks specific) in exchange for reduction in bundle size.

marvinhagemeister commented 4 years ago

The class API is an integral part of our core. It is not an add-on like our the hooks implementation, so we can't just remove it via build scripts currently.

That said if you want to take up the work of extracting classes, we're happy to guide you along the way. Most of the class specific code can be found in diff(). That's likely where you'd need to start 👍

Rafi993 commented 4 years ago

Awesome. I will try creating a PR for this.

marvinhagemeister commented 4 years ago

Sorry for closing this one prematurely.

Rafi993 commented 4 years ago

No issues

sventschui commented 4 years ago

You might want to have a look at #2102

JoviDeCroock commented 4 years ago

Hmm, #2102 moves a few internals but we still have to test if it actually improves performance.

The most important part to preserve functionality will be to move _forceUpdate to the vnode so useReducer can call vnode.forceUpdate() instead of setState. About the components I still have to think about the best approach.

ghost commented 4 years ago

Would anyone mind kindly confirming that this is a storybook/preact issue, and not a preact issue: https://github.com/storybookjs/storybook/issues/10140#issuecomment-623000179 ?

marvinhagemeister commented 4 years ago

@CaffeinateOften Please don't hijack issues that are completely unrelated and open a new one instead. Otherwise it quickly becomes impossible for us maintainers to track them.