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.

sharedWorker.port.onmessage doesn't seem to be covered by NgZone

See original GitHub issue

🐞 bug report

Affected Package

The issue is caused by package @angular/zone.js

Is this a regression?

I don’t think so.

Description

We are using a SharedWorker to synchronize data between multiple open tabs. We ran into some very weird behaviors where the displayed data would only change if you e.g. click on the page (= trigger for change detection).

We could finally track it down to the following root:

sharedWorker = new SharedWorker('shared-worker.js');
sharedWorker.port.onmessage = (event: MessageEvent) => {
    // here is some logic to transport the received data around the application via rxjs Subjects
    // these subjects didn't trigger change-detection anywhere
}

It could be fixed by letting it manually run in the zone (zone: NgZone)

sharedWorker = new SharedWorker('shared-worker.js');
sharedWorker.port.onmessage = (event: MessageEvent) => {
    this.zone.run(()=> {
        // here is some logic to transport the received data around the application via rxjs Subjects
       // now change-detection is everywhere triggered as expected
     });
}

🔬 Minimal Reproduction

I currently don#t have time to create a full reproduction in stackblitz - if necessary I will add it later on…

🌍 Your Environment

Angular Version:


Angular CLI: 10.0.0
Node: 14.4.0       
OS: win32 x64      

Angular: 10.0.2
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router, service-worker
Ivy Workspace: Yes

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.1000.0
@angular-devkit/build-angular     0.1000.0
@angular-devkit/build-optimizer   0.1000.0
@angular-devkit/build-webpack     0.1000.0
@angular-devkit/core              10.0.0
@angular-devkit/schematics        10.0.0
@angular/cdk                      10.0.1
@angular/cli                      10.0.0
@ngtools/webpack                  10.0.0
@schematics/angular               10.0.0
@schematics/update                0.1000.0
rxjs                              6.5.5
typescript                        3.9.5
webpack                           4.43.0

zone.js                               0.10.3

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
JiaLiPassioncommented, Jul 3, 2020

@Dassderdie , yeah, you are right, there are several other bundles are missing there too, I will add it to the document, thanks.

0reactions
angular-automatic-lock-bot[bot]commented, Aug 3, 2020

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JavaScript: How to know if a connection with a shared worker ...
Looking at the specification the objects of the connections variable doesn't seem to hold a property/function to check if the connection is ...
Read more >
SharedWorker - Web APIs - MDN Web Docs
The SharedWorker interface represents a specific kind of worker that can be accessed ... postMessage() and port.onmessage , respectively:.
Read more >
Cross-Tab Communication in JavaScript using a SharedWorker
In order to accept a message, we'll need to listen for messages on this port using the onmessage event listener. When our onmessage...
Read more >
Incident Response - Hybrid Analysis
Sends traffic on typical HTTP outbound port, but without HTTP header. details: TCP traffic to 220.248.108.22 on port 443 is sent without HTTP...
Read more >
Angular 2 Example - Component Communication Countdown ...
cancelFn) { throw new Error('Task does not support cancellation, ... Safari 7.0 has non-configurable own 'onmessage' and friends properties on the socket ...
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