Skip to content

Conversation

@tbouffard
Copy link
Member

@tbouffard tbouffard commented Feb 10, 2025

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

…tions on tree-shaking [POC]

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.
@tbouffard tbouffard added the chore Build, CI/CD or repository tasks (issues/PR maintenance, environments, ...) label Feb 10, 2025
@coderabbitai
Copy link

coderabbitai bot commented Feb 10, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@sonarqubecloud
Copy link

@tbouffard
Copy link
Member Author

The POC is completed.
The PR description includes all information collected during the POC, so the PR can be closed.

@tbouffard tbouffard closed this Feb 11, 2025
@tbouffard tbouffard deleted the poc/experiment_tree-shaking_translations branch February 11, 2025 06:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore Build, CI/CD or repository tasks (issues/PR maintenance, environments, ...)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant