question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support zoneless applications

See original GitHub issue

I’m submitting a…

[X] Bug report

Current behavior

When used within Angular Element application without zone.js, translation pipe does not work, translations keys are not translated nor visible.

What i tried already:

  • run ChangeDetectorRef.markForCheck() or ChangeDetectorRef.detectChanges() in various app lifecycles hooks ngOnInit, ngAfterViewInit, ngOnChanges
  • run ApplicationRef.tick() in various app lifecycles hooks ngOnInit, ngAfterViewInit, ngOnChanges
  • change ChangeDetectionStrategy to OnPush

but nothing helps…

Expected behavior

To work transloco as expected i.e. translate keys into texts.

Minimal reproduction of the problem with instructions

  1. scaffold new Angular Elements app
  2. import '@webcomponents/webcomponentsjs/custom-elements-es5-adapter.js' in src\polyfills.ts
  3. import 'document-register-element' in src\polyfills.ts
  4. remove zone.js from src\polyfills.ts
  5. add { ngZone: 'noop' } in src\main.ts

and here is a demo https://stackblitz.com/edit/angular-xb7xmc

What is the motivation / use case for changing the behavior?

To work transloco translations in Angular Elements (Web Components) applications without zone.js.

Environment

Angular version: 9.1.3

Browser:
- [X] Chrome (desktop) version 81.0.4044.129 (Official Build) (64-bit)

Others:
- @angular/elements: 9.1.3
- document-register-element: 1.14.3
- @webcomponents/webcomponentsjs: 2.4.3

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11

github_iconTop GitHub Comments

1reaction
k3nseicommented, Oct 23, 2020

@emzet, @cgatian, @itayod here is a working example https://stackblitz.com/edit/angular-hbppzv?file=src/app/app.module.ts

All the magic is here. This solution was tested on very big application. That app is configured to be zoneless and all is working as expected. The trick is to delay a bit change detection process to prevent races.

this.translocoService
  .selectTranslation()
  .pipe(
    delay(0, animationFrameScheduler),
    takeUntil(this.destroyed$)
  ).subscribe(() => this.applicationRef.tick());
0reactions
cgatiancommented, Jun 25, 2020

Oh wow, I know that @ngrx/component is going to enable a lot more apps to opportunity to drop zone. And the lack of Angular Elements without zone. That hurts.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Going fully Zone-Less! High-Performance Angular ... - YouTube
Go fully Zone-Less in your Angular application in the post IVY era!! The async pipe is boring! Understand the guts of Angulars change ......
Read more >
Quantum Angular: Maximizing Performance by Removing Zone
If your application needs a special performance target, disabling Zone can help deliver better performance for your application: an example ...
Read more >
NgZone - Angular
A zone is an execution context that persists across async tasks. You can think of it as thread-local storage for the JavaScript VM....
Read more >
Reactive Angular with ngrx/component - Chris Kohler
Zone less approach in Angular; Change detection in a reactive application; Async Pipe; ngrx PushPipe and let directive ...
Read more >
Zenless Zone Zero Official Site
Zenless Zone Zero is a brand new action game. The story takes place in the near future, where a mysterious natural disaster known...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found