Skip to content

--localize produces files with same hash values, even though file contents are different #16526

Closed

Description

@mstawick

🐞 Bug report

Angular CLI: 9.0.0-rc.7, Angular: 9.0.0-rc.7

Command (mark with an x)

  • new
  • build
  • serve
  • test
  • e2e
  • generate
  • add
  • update
  • lint
  • xi18n
  • run
  • config
  • help
  • version
  • doc

Is this a regression?

Not sure, I haven't used localization with prior versions.

Description

If I have two locales configured, build process will generate two sets of files, one per locale, but the file names (including hash parts) are identical for corresponding files in both sets, even though contents of the files are different due to translations.

🔬 Minimal Reproduction

Have a project with two locales set up, and translated messages in place. Then build it using --localize option and compare file names in resulting localized builds.

🔥 Exception or Error

No error.

🌍 Your Environment


Angular CLI: 9.0.0-rc.7
Node: 12.14.0
OS: linux x64

Angular: 9.0.0-rc.7
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, localize, platform-browser
... platform-browser-dynamic, router
Ivy Workspace: Yes

Package                            Version
------------------------------------------------------------
@angular-devkit/architect          0.900.0-rc.7
@angular-devkit/build-angular      0.900.0-rc.7
@angular-devkit/build-optimizer    0.900.0-rc.7
@angular-devkit/build-webpack      0.900.0-rc.7
@angular-devkit/core               9.0.0-rc.7
@angular-devkit/schematics         9.0.0-rc.7
@angular/cdk                       9.0.0-rc.6
@angular/material                  9.0.0-rc.6
@angular/material-moment-adapter   9.0.0-rc.6
@ngtools/webpack                   9.0.0-rc.7
@schematics/angular                9.0.0-rc.7
@schematics/update                 0.900.0-rc.7
rxjs                               6.5.3
typescript                         3.6.4
webpack                            4.41.2

Activity

  1. added this to the v9-candidates milestone on Jan 3, 2020
  2. removed this from the v9-candidates milestone on Jan 3, 2020
  3. modified the milestone: Backlog on Jan 3, 2020
  4. filipesilva commented on Jan 3, 2020

    @filipesilva
    Contributor

    I think this is a regression because localization used to happen on an earlier part of the build pipeline, but now happens as a post-processing step.

  5. mstawick commented on Jan 8, 2020

    @mstawick
    Author

    FYI, it messes up source maps as well.

  6. modified the milestones: v9-candidates, Backlog on Jan 23, 2020
  7. pinned this issue on Jan 29, 2020
  8. filipesilva commented on Jan 29, 2020

    @filipesilva
    Contributor

    Pinning this issue as we don't yet have a resolution and it will likely affect 9.0.

    This might be especially bothersome if you have caching based on the hashes, and one doesn't change when you only do translation file changes. The workaround is to introduce code differences in each affected bundle source. This isn't ideal, and we're working on a fix.

  9. timofei-iatsenko commented on Jan 31, 2020

    @timofei-iatsenko

    One of the possible solutions might be re-hashing file names and replace links in index.html as an additional step in localize postprocessor.

    This also may have a benefit of implementation flat mode for localize, by adding locale code to a filename:

    index.en.html
    main.en.%hash%.js
    index.pl.html
    main.pl.%hash%.js
    

    But the open question is how without too dirty hacks teach webpack runtime to fetch correct lazy chunks, because their names will be also changed by hashing.

  10. timofei-iatsenko commented on Jan 31, 2020

    @timofei-iatsenko

    BTW it looks not so complicated to just replace names of lazy chunks in runtime bundle

    // example webpack runtime code
    /******/ 	function jsonpScriptSrc(chunkId) {
    /******/ 		return __webpack_require__.p + "" + ({"cars-search-ui":"cars-search-ui","filestack-client":"filestack-client","flights-api-parsing":"flights-api-parsing","flights-search-ui":"flights-search-ui","td":"td"}[chunkId]||chunkId) + ".js"
    /******/ 	}

    But the question about how ugly is that and does that kind of solution acceptable for that project is still opened.

  11. timofei-iatsenko commented on Jan 31, 2020

    @timofei-iatsenko

    Well, I see that you actually doing this for differential loading. So it shouldn't be a big deal to add localizing to this as well.

  12. unpinned this issue on Feb 4, 2020
  13. clydin commented on Feb 4, 2020

    @clydin
    Member

    The underlying functional issue is that the hashes do not change if only translation file changes are made (and no code changes). In this situation and if the application deployment uses permanent caching strategies for the files then an end-user that has previously cached the file would then not see the updated translation. This PR (#16817) corrects this issue by incorporating the content of used translation files into the file hash calculation. This will prevent the stale cache issue from occurring.

    As an aside, Webpack's calculated hash values are not a direct hash of the final content but rather a complex internal calculation based on a variety of factors including such elements as modules referenced and plugins present in the Webpack configuration.

  14. timofei-iatsenko commented on Feb 5, 2020

    @timofei-iatsenko

    Just out of curiosity, does it have any sense to have "complex internal calculation based on a variety of factors" when presence of a plugin or a module anyway will change output and therefore change hash and if no, so there no sense to change a hash (content is not changed).

    An aside changes made in PR #16817 will introduce changes in hash for every language even if you change one line in one of them, forcing users to redownload everything.

  15. clydin commented on Feb 5, 2020

    @clydin
    Member

    That is the behavior of Webpack itself and is not particular to the Angular CLI. A change in the versions of underlying Webpack dependent packages can cause the hash value to change, for instance.

    As to the hash changes, that is true assuming no code changes were made within the application release and only changes to translations for one particular locale were made for that release and none of the build tools were updated since the prior release. While all of this is a possibility, it was also considered to be far more uncommon than common; while the elimination of the potential for stale applications is a necessity.
    Removing the use of webpack’s file hashing and moving the file name creation to a later stage of the build process is currently planned. However, such a change is out of scope within the current release candidate period.

  16. angular-automatic-lock-bot commented on Mar 7, 2020

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  17. locked and limited conversation to collaborators on Mar 7, 2020
  18. removed their assignment
    on Jun 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions