chore: measure impact of a configurable i18n abstraction over Transactions on tree-shaking [POC] by tbouffard · Pull Request #668 · maxGraph/maxGraph

DISCLAIMER

  • this PR is for exploration and information only
  • it is not intended to be merged

Context

This experiment is part of the investigation for #665.

A significant portion of the codebase relies directly on the Translations module, which retrieves resources via MaxXmlRequest. Both of these components add considerable weight to the final application bundle, even when the maxGraph i18n features aren't being used.

Additionally, this tight coupling makes it difficult to integrate alternative i18n solutions, as it requires setting up a custom bridge between the application's i18n mechanism and maxGraph.

Important

This POC is only an evaluation and the final implementation may differ from that described in this PR.
Derived from mxGraph, the configuration of Translations is global, and this PR only modifies the way in which global configuration is carried out.
It is probably possible to switch to local configurations, but this would require significant internal changes, in particular to inject the configuration into the various places where it is used.

High-level solution

Don't depend on Translations directly in the code.
Introduce an "I18n" abstraction as we did with Logger for MaxLog.

A configurable instance of the "I18nProvider" is set on GlobalConfig which is then use everywhere in the code.
The configuration related to Translations is no longer in Client but in a new dedicated TranslationsConfig global object.

By default, use a "no op" i18n provider, so there is no dependency on Translations and MaxXmlRequest, which has a possible impact on the tree-shaking.

Results

✔️ ts-example and storybook stories are working as before when using the new "no op" i18n provider.

❓ The translation resources are not available in maxGraph, so there is currently no need to test that the actual usage of the former Translations implementation through its new i18n provider.

✔️ Bundle size reduction around 5 kB

Package Before Now
ts-example 445.20 kB 440.25 kB
ts-example without defaults 441.17 kB 436.22 kB
js-example 486.6 kB 483.54 kB
js-example without defaults 463.1 kB 457.43 kB

Note: js-example use Codecs, and the Codec class still imports Translations directly in this POC (it calls a specific method of Translations which is currently not generalized in the I18nProvider). This may explain why the size decrease is lower than for other examples.

Notes

Covers #665