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

Directive with missing translation causes browser freeze #1281

Open
Grolleau opened this issue Jan 8, 2021 · 2 comments
Open

Directive with missing translation causes browser freeze #1281

Grolleau opened this issue Jan 8, 2021 · 2 comments

Comments

@Grolleau
Copy link

Grolleau commented Jan 8, 2021

Current behavior

We are adding the Matomo web tracking solution on our project.

When a page contains a missing translation, the directive is called thousands of times until Firefox ask for killing the script.
If we use the pipe instead of the directive, there is no problem.

I guess that problem is related to MutationObserver added on DOM, by Matomo, to track users actions.

Expected behavior

Missing translation with translate directive should not trigger infinite loop

How do you think that we should fix this?

Always set node.lastKey with key instead of setting it when translation is different from key.
The guard clause of updateValue function should prevent infinite updates.

`
updateValue(key: string, node: any, translations: any) {
if (key) {
if (node.lastKey === key && this.lastParams === this.currentParams) {
return;
}

  this.lastParams = this.currentParams;

  let onTranslation = (res: string) => {
    if (res !== key) {
      node.lastKey = key;
    }
    ...
  }

}
`

Minimal reproduction of the problem with instructions

https://stackblitz.com/edit/angular-acbh8j

Environment


ngx-translate version: 12.1.0
Angular version: 8.1.4


Browser:
- [ X] Chrome (desktop) version 87.0.4280.141
- [X ] Firefox version 84.0.1

 
For Tooling issues:
- Node version: v14.15.0
- Platform:  Windows
@Grolleau Grolleau changed the title Directive with missing translation causes browser freeze Directive with missing translation cause browser freeze Jan 8, 2021
@Grolleau Grolleau changed the title Directive with missing translation cause browser freeze Directive with missing translation causes browser freeze Jan 8, 2021
@joscht
Copy link

joscht commented Mar 12, 2021

We are having the same behaviour in combination with simplebar (https://github.com/Grsmto/simplebar). Probably simplebar adds some Observer/Listener to the DOM which in combination with ngx-translate leads to an infinite loop.
Ist there a chance this pull request will be merged any time soon or the issue will be fixed in any other way?

@mario0511
Copy link

mario0511 commented Jul 6, 2021

I have the same issue.

By using a single translate in a lazyloaded simplebar area, after 4th 5th load, the window freezes completely.
Even if i close the tab, my systems stays under load. Have to restart the browser for the system to calm down.

Currently using: Angular 11.2.10 / Simplebar 2.3.4 / ngx-translate 13.0.0

EDIT: I found out that the window freeze occurs if a translation-key does not exist in the translation file. f.e. "parent.sub.translationKey"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants