Repository navigation
Do not embed i18n message catalog in TransferState of SSR pages - #6348
saschaszott wants to merge 9 commits into
Conversation
nwoodward
left a comment
There was a problem hiding this comment.
Thanks @saschaszott! The code looks good, and I confirmed that it behaves as described with a <link rel="preload" …> link in the <head> section instead of loading NGX_TRANSLATE_STATE in the TransferState.
One question, are the changes in .github/workflows/docker.yml part of the PR?
Yes, because the old check relies on a translation value ( |
|
OK, I see now. Thanks for clarifying that. |
|
Hi @saschaszott, |
|
In the meantime, the changes from PR #5653 have been merged into main. I need to better understand these changes before I can resolve the new merge conflict in this PR. |
|
@kanasznagyzoltan , @alanorth : I'm trying to resolve the current merge conflict in this PR. The goal of this PR is to remove the full i18n message catalog from the SSR transfer state. Is this still possible given the changes introduced by the merged PR #5653? |
|
@tdonohue, since we need to integrate the changes from this PR with those introduced in #5653 (which is a new feature in DS11), I think it will be difficult to backport these changes to older DS versions if we resolve the merge conflict in this PR. Would it be a better approach to change the target branch of this PR to https://github.com/DSpace/dspace-angular/tree/dspace-10_x and create a new PR that would allow us to easily integrate the changes into main? |
|
@saschaszott yes, I think removing the i18n catalog from the TransferState in #6348 is still possible, and it shouldn't be much work. #5653 already has a full client-side path: when there's nothing in the TransferState, the browser loader fetches the base file plus the override files of the active theme chain and merges them. The build records which themes ship a file for which language ( Two things to keep in mind:
Retargeting #6348 to |
@saschaszott : Yes, it sounds like we should have separate PRs for 10.x (and below) and |
|
@saschaszott I've opened the follow-up for the theme file hashes: #6543. |
References
Description
Removes the complete i18 message catalog from the SSR TransferState. Instead, the server adds a
<link rel="preload" …>element for the content-hashed translation file, and the browser waits for it to be loaded before application bootstrapping. Hanging requests and network timeouts are handled properly and can never block the app bootstrap.Impact: SSR responses shrink by ~300 kB per page. The translation file is requested once and then served from the browser cache, as its name contains a content hash.
Instructions for Reviewers
List of changes in this PR
TranslateServerLoaderno longer writes the i18n message catalog to the TransferState. Instead, it adds<link rel="preload" as="fetch" crossorigin="anonymous" href="assets/i18n/<lang>.<hash>.json">to the document head (right after<base>, so the relative URL resolves correctly)TranslateBrowserLoaderalways loads the messages viaHttpClientgetTranslationFileName(), so server (preload link) and browser (HTTP request) use the same name of the i18n translation fileBrowserInitServicewaits in the app initializer until the message catalog for the current language is loaded (avoids message keys briefly showing up when the client renders)TRANSLATIONS_TIMEOUT_MS), so a hanging request (e.g. fetching the authenticated user's language, or the translation file itself) can never block the app. A log message is printed. The app bootstraps anyway and the translation messages are applied once they're loaded.NGX_TRANSLATE_STATEkey (ngx-translate-state.ts)How to test
NGX_TRANSLATE_STATEis no longer present in<script id="dspace-angular-state"><head>element contains the preload link forassets/i18n/<lang>.<hash>.jsonnav.login) should flash before the translated texts appearassets/i18n/<lang>.<hash>.jsonin the browser's dev tools (Network → "Block request URL") and reload: after at most 5 seconds the app becomes interactive and "Failed to load translation message catalog" is logged to the consoleAI Disclosure (REQUIRED)
This PR was created with the assistance of Claude (LLM Opus 5.5, medium effort). Claude was used to better understand and analyze the problem and to assist in the implementation process of this PR. All changes were reviewed in detail and tested by me.
Were AI tools used in the creation of this PR?
Checklist
This checklist provides a reminder of what we are going to look for when reviewing your PR. You do not need to complete this checklist prior creating your PR (draft PRs are always welcome).
However, reviewers may request that you complete any actions in this list if you have not done so. If you are unsure about an item in the checklist, don't hesitate to ask. We're here to help!
mainbranch of code (unless it is a backport or is fixing an issue specific to an older branch).npm run lintnpm run check-circ-deps)package.json), I've made sure their licenses align with the DSpace BSD License based on the Licensing of Contributions documentation.