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

[Deprecated] Vite as Volto bundler #6320

Closed
tisto opened this issue Sep 25, 2024 · 4 comments · May be fixed by #6543
Closed

[Deprecated] Vite as Volto bundler #6320

tisto opened this issue Sep 25, 2024 · 4 comments · May be fixed by #6543

Comments

@tisto
Copy link
Member

tisto commented Sep 25, 2024

PLIP (Plone Improvement Proposal)

Responsible Persons

Proposer: Víctor Fernández de Alba (@sneridagh)

Seconder: Timo Stollenwerk (@tisto)

Important

This PLIP is being superseded by: #6638
Please read the rationale behind it in the following section.

@sneridagh UPDATE 02/01/2025

I've been exploring the actual implementation of this PLIP during the last months. I want to share my experience and findings of this task. You can find the result of the PoC I've managed to put together in #6543. If you want to try it, you are welcome to do so.

If you want the TL;DR summary, jump to the "conclussion" section if you want to skip the nitty gritty details.

The PoC works, both in the client and in SSR, RAZZLE has been removed from the build, and Volto runs powered with Vite. We created a Vite plugin that had all the customizations that we did to the RAZZLE build. We had to rewrite some parts of Volto, because how Vite works internally, and because we were using some libraries that were Webpack-only.

  • Remove @loadable/component and start using React.lazy instead.
  • Remove all the barrel imports, move to use direct imports everywhere.
  • Swich the use of some legacy libraries that are not ESM-ready to a more modern ones

We discovered in the process that AsyncConnect (the library that makes possible Redux requests in SSR) was incompatible with React.lazy so we cannot lazy load any of the routes, and that we will have to remove it in favor of the new data acqurire system described in #6324 and #4347.

At the same time, while trying to start to fix the Cypress tests (since it was the next step after the build "worked"), that I realised that all the component lifecycle rendering timings were off. React.lazy and Suspense does its job well, but they do not work the same way that @loadable/component do, therefore, the timing issues. Also, we opted by lazy load everything in Volto at some point, and this kind of worked because of the barrel imports. Once all the components have to be lazy imported, then components start to pop up at a different time everywhere. This is dramatic, because the user experience gets spoiled as well, because of this.

The outcome from this is that we should deal with a complete different app, with different timings, having to think from scratch what and when to lazy load a component, and the rationale behind, while fixing the user experience as well.
If we were to do so, we would have need to do other changes that we want to do also to the app, because, these changes will change again the shape of the app, forcing (again) to recheck the timings and tame yet another different app.

In summary, these are the changes that must happen at the same time of this PLIP:

Conclusion

If we have to achive all of the above items, we have to "literally" rewrite not only the internal architecture of Volto but the full set of components while taking care that the user "feel" experience of the app continues to be the same. By doing this, we will be replacing every single piece of code from Volto with a new one ending up with a complete different thing.

Therefore, in the wake of a complete revisit of the whole app from the ground up, and given our limited resources, it would be quicker to already put all this effort in building a completely new app. In my opinion, this would be more efficient, clearer, and effective than refactor the whole Volto in a multi-year-long effort.

So my proposal is to close this PR, and continue towards this new app.


Abstract

Volto, as any other modern JS application, relies on a bundler for producing builds of the transpiled and transformed code for production deployments and support for a full fledged development environment.

Volto is using currently Razzle as a bundler, however it has become obsolete and completely abandoned in the last years. This situation created a huge technical debt in a key element of the product. Volto can’t use some of the latest tooling or development experience improvements that the React ecosystem has provided during the last years.

After a study of the alternatives in the React ecosystem, it’s been decided to use Vite. This bundler has become the standard “de facto” bundler of many modern JS frameworks and apps. It’s flexible, pluggable, extensible and fast. It does not use Webpack (since Webpack is becoming problematic lately), but ESbuild and Rollup for the production bundling.

Assumptions

Vite is ESM, so it’s also future ready. This, along with the fact that it does not uses Webpack forced us to take some decisions and push for some breaking changes. All of them have a good reason behind them and in summary, it will resut in better and modern code using ESM and React artifacts, instead of relying on Razzle and Webpack magic.

Breaking changes

  • Config from project - create-addons-loader will no longer load the config from the project itself.
  • lodash-es must be used instead of lodashbecause the latter is not compatible with ESM.
  • @loadable/component and Volto’s Loadables support only works for Webpack based builds, so they will be replaced them with standard React lazy instances.
  • The index.js barrel import files are removed for allowing the build to better chunk splitting thanks to the above.
  • doesNotContainClick from semantic-ui-react will be adopted in now core
  • Globals __CLIENT__ and __SERVER__ have to be replaced with import.meta.env.SSR

All of them will be deprecated in Volto 18 so their use is already discouraged from Volto 18 on.

Deliverables

Removal of all Razzle artifacts, Webpack plugins, unused Babel plugins and config. Removal of related libraries from the devDependencies.

Except for the above deprecations and breaking changes the code and libraries used in Volto should not be changed, defining a baseline in which base future improvements that will be taking place in other PRs.

The result must pass all the existing tests and be linted following the existing configuration.

Risks

The breaking changes introduced will force to run upgrade steps not only in the project's code, but also in add-ons. All Razzle artifacts will have to be removed or updated. Add-ons maintainers will have to release major versions of them, and maintain compatibility matrixes to communicate properly which versions are ready for the new Vite buids.

We need to write outstanding documentation in order to make the process the smoothest possible.

Proposal & Implementation

The current work is at 70% and done in this PR:
#6050

Participants

Víctor Fernández de Alba (@sneridagh)
Piero Nicolli (@pnicolli)
Volto Team (@plone/volto-team)

@tisto tisto added this to the Plone 7.0 milestone Sep 25, 2024
@sneridagh sneridagh changed the title Vite Vite as Volto bundler Sep 27, 2024
@sneridagh sneridagh linked a pull request Sep 27, 2024 that will close this issue
@github-project-automation github-project-automation bot moved this to Needs discussion in Volto Team Meeting Sep 27, 2024
@sneridagh sneridagh moved this from Needs discussion to Plan approved in Volto Team Meeting Sep 27, 2024
@sneridagh
Copy link
Member

Disclaimer

This is an strategic PR, so it's overseen, done and implemented by the Volto Team.

@davisagli
Copy link
Member

@sneridagh We obviously don't have much choice about whether to switch to something else, and I'm grateful for the efforts to find a path forward.

It's unfortunate that the breaking changes will be enough to make it difficult to maintain an addon that supports both the old and new way. Can we do anything to help make this path smoother, like automatic fixers to take care of some of the changes?

Vite is ESM, so it’s also future ready.

I'm only vaguely aware of what ESM is. Can you say a bit more about what the consequences of this change are?

doesNotContainClick from semantic-ui-react will be adopted in now core

This one sounds more related to #6321 than to Vite.

Globals CLIENT and SERVER have to be replaced with import.meta.env.SSR

Is it possible to add a forward-compatible import.meta.env object in Volto 18 with Razzle, so that addons can make this change already?

@sneridagh
Copy link
Member

@davisagli thanks for taking a look!
For sure we have to develop further the PLIP text, I will complete it and improve it.

Regarding having an add-on that supports both: I still think that we could achieve that. Please take a look at:
#6350

It's a summary of deprecations that we should issue in Volto 18. They are related with Plone 7 / Vite build. The idea is adding alternatives for each deprecation so the community can start being prepared for Plone 7.

I don't know if the import.meta is a ESM thing, so in a non-ESM build it will complain. We should investigate and find proper alternatives for all.

@sneridagh sneridagh linked a pull request Dec 16, 2024 that will close this issue
@sneridagh sneridagh moved this to In progress in Volto Roadmap Dec 17, 2024
@sneridagh sneridagh changed the title Vite as Volto bundler Vite as Volto bundler (deprecated Feb 2, 2025
@sneridagh sneridagh changed the title Vite as Volto bundler (deprecated [Deprecated] Vite as Volto bundler Feb 2, 2025
@sneridagh
Copy link
Member

Closing in favor of #6638
See reasoning in the description.

@github-project-automation github-project-automation bot moved this from Plan approved to Done in Volto Team Meeting Feb 2, 2025
@github-project-automation github-project-automation bot moved this from In progress to Done in Volto Roadmap Feb 2, 2025
@github-project-automation github-project-automation bot moved this from In Progress to Done in Plone 7 Roadmap Feb 2, 2025
@sneridagh sneridagh removed this from Volto Roadmap Feb 2, 2025
@sneridagh sneridagh removed this from the Plone 7.0 milestone Feb 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants