Skip to content

Fix device filter being ignored (missing await on util.isEmpty) - #295

Open
TekScene wants to merge 1 commit into
petersem:masterfrom
TekScene:fix/device-filter-await
Open

TekScene wants to merge 1 commit into
petersem:masterfrom
TekScene:fix/device-filter-await

Conversation

@TekScene

@TekScene TekScene commented Sep 7, 2026

Copy link
Copy Markdown

Fixes #283 — "Filter by device(s) no longer filtering".

Cause

utility.isEmpty() is declared async, so it always returns a Promise, which is always truthy. The guard added in 3f3bab9 calls it without await:

if(devices.length > 0 && !util.isEmpty(medCard.playerDevice) && ...) okToAdd = false;

!util.isEmpty(...) therefore evaluates to false for every session, so the whole condition short-circuits and okToAdd is never set to false by the device filter. Result: all devices are shown regardless of the "Filter by device(s)" setting — matching the reports that rolling back to v1.21.9 (before that commit) restores correct behaviour.

Quick demonstration of the underlying behaviour:

!isEmpty("Shield")           -> false   // Promise is truthy
!isEmpty("")                 -> false
!(await isEmpty("Shield"))   -> true    // correct

Fix

Await the call, matching how util.isEmpty is used everywhere else in plex.js (e.g. lines 274, 321, 736). This is the only unawaited call site in the codebase.

if(devices.length > 0 && !(await util.isEmpty(medCard.playerDevice)) && ...) okToAdd = false;

The surrounding code is already inside an async reduce callback, so await is valid here. The null-safety intent of the original commit is preserved: sessions with no Player.title still skip the device check instead of throwing on .toLowerCase().

util.isEmpty is async, so the unawaited call in the device filter check
always returned a truthy Promise, making !util.isEmpty(...) always false.
That short-circuited the device filter, so every playing device was shown
regardless of the 'Filter by device(s)' setting.

Fixes petersem#283

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

Filter by device(s) no longer filtering

1 participant