[Chrome] MediaObserver asObservable() emit wrong events on breakpoints
See original GitHub issueBug Report
What is the expected behavior?
When I resize the screen from 959px to 960px, MediaObserver.asObservable() should emit a MediaChange event with mqAlias=“md”
What is the current behavior?
When I resize the screen from 959px to 960px, MediaObserver.asObservable() emits (among others) 2 MediaChange events with mqAlias=“md” and mqAlias=“sm”
What are the steps to reproduce?
A component with
public ngOnInit() {
this.watcher = this.mediaObserver.asObservable()
.subscribe((changes: MediaChange[]) => {
console.log(changes)
})
}
What is the use-case or motivation for changing an existing behavior?
When I resize slowly, MediaObserver.media$ does not always emit an event when breakpoints are crossed. I think it may be related.
Is there anything else we should know?
It may be related to the recent changes about the breakpoints (i.e. max-width: 959.99 instead of 959) fxLayout version: 7.0.0-beta.24
Issue Analytics
- State:
- Created 4 years ago
- Reactions:23
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Angular Flex-Layout using MediaObserver | by Duncan Faulkner
We set up an observable to the mediaObserver using the asObservable(). When the browser is resized, we get the currently set breakpoint from...
Read more >UNPKG - @angular/flex-layout
elementMap.get(element);\n if (!bpMap) {\n bpMap = new Map().set(bp, ... 'real' breakpoints and emit events\n * to trigger stream notification\n */\n ...
Read more >Javascript not working but works fine when put breakpoints ...
You are assigning a keyup event handler in an onchange. That will not work since onchange does not trigger until you leave the...
Read more >Issues · angular/flex-layout · GitHub
[Chrome] MediaObserver asObservable() emit wrong events on br. ... fxLayoutGap in responsive mode breaks without original non-breakpoint value provided can ...
Read more >Package Diff: @angular/flex-layout @ 7.0.0-beta.19 .. 7.0.0 ...
asObservable() ` with syntax like media. ... The MQA proxies mediaQuery change events and notifies the ... + * Used in MediaMarshaller and...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Same here.
This is my code
In Chrome, when I resize fast (from lg to md and back), I get the following outputs
This is expected (except that all events are emitted twice).
When resizing slowly, I get the following outputs
As you can see, both “md” and “lg” are reported.
In Firefox, things get even weirder:
First, when making the window smaller, no ‘single’ mqAlias is reported, but only ranges. In contrast to the initial result, the “lg” and “gt-md” aliases are removed, but only the “lt-lg” alias is added. I would expect that also the “md” alias is added.
Then right after the first event, a second event gets fired with the correct “md” alias added.
When making the window larger, the “gt-md” alias is added, but not the “lg” alias. The “md” alias is not removed. I would expect that “md” would also be removed and “lg” would be added.
Then right after the first event, a second event gets fired with the “lg” alias added, but the “md” alias is still not removed.
I’ve filed a ticket with the Chromium team, and they’ve identified the root cause and assigned priority to the case, which hopefully means we can get this addressed in one of the next major versions.
Tracking: https://bugs.chromium.org/p/chromium/issues/detail?id=1285532 (please do not spam the ticket)