Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions packages/upload-media/src/feature-detection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ let cachedResult: FeatureDetectionResult | null = null;
* 2. SharedArrayBuffer support (required for WASM threading)
* 3. CSP compatibility for blob URL workers (required for inline worker creation)
* 4. Device memory (disables on devices with ≤2 GB RAM)
* 5. Hardware concurrency (disables on devices with fewer than 4 CPU cores)
* 6. Network conditions (disables when data saver / reduced data mode is on or connection is 3g/2g/slow-2g)
* 5. Hardware concurrency (disables on devices with fewer than 2 CPU cores)
* 6. Network conditions (disables when data saver / reduced data mode is on or connection is 2g/slow-2g)
* 7. Web Worker support (baseline requirement)
*
* Results are cached after the first call. Use `clearFeatureDetectionCache()` to reset.
Expand Down Expand Up @@ -93,7 +93,7 @@ export function detectClientSideMediaSupport(): FeatureDetectionResult {
if (
typeof navigator !== 'undefined' &&
'hardwareConcurrency' in navigator &&
navigator.hardwareConcurrency < 4
navigator.hardwareConcurrency < 2
) {
cachedResult = {
supported: false,
Expand All @@ -115,8 +115,7 @@ export function detectClientSideMediaSupport(): FeatureDetectionResult {
}
if (
connection.effectiveType === 'slow-2g' ||
connection.effectiveType === '2g' ||
connection.effectiveType === '3g'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess 3G gave us Youtube on our devices 😄

This makes sense to me.

Apparently 2g vs 3g is the difference between 128kbps and 8mbps depending on who you ask :)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: We also disable for low data mode, so users who are on a data budget won't get the feature.

connection.effectiveType === '2g'
) {
cachedResult = {
supported: false,
Expand Down
13 changes: 6 additions & 7 deletions packages/upload-media/src/test/feature-detection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,9 @@ describe( 'feature-detection', () => {
expect( result.supported ).toBe( true );
} );

it( 'returns not supported when hardware concurrency is less than 4', () => {
it( 'returns not supported when hardware concurrency is less than 2', () => {
Object.defineProperty( navigator, 'hardwareConcurrency', {
value: 2,
value: 1,
configurable: true,
} );

Expand All @@ -183,9 +183,9 @@ describe( 'feature-detection', () => {
expect( result.reason ).toContain( 'insufficient CPU cores' );
} );

it( 'returns supported when hardware concurrency is 4 or more', () => {
it( 'returns supported when hardware concurrency is 2 or more', () => {
Object.defineProperty( navigator, 'hardwareConcurrency', {
value: 4,
value: 2,
configurable: true,
} );

Expand Down Expand Up @@ -218,16 +218,15 @@ describe( 'feature-detection', () => {
expect( result.reason ).toContain( 'too slow' );
} );

it( 'returns not supported when connection is 3g', () => {
it( 'returns supported when connection is 3g', () => {
Object.defineProperty( navigator, 'connection', {
value: { saveData: false, effectiveType: '3g' },
configurable: true,
} );

const result = detectClientSideMediaSupport();

expect( result.supported ).toBe( false );
expect( result.reason ).toContain( 'too slow' );
expect( result.supported ).toBe( true );
} );

it( 'returns not supported when connection is slow-2g', () => {
Expand Down
Loading