Skip to content

Commit

Permalink
Classify "unknown" mobile devices as phones (#955)
Browse files Browse the repository at this point in the history
This deals with an edge case of mobile-detect. See commentary.
  • Loading branch information
gigabo authored Sep 29, 2017
1 parent 466ef77 commit 5ced5ec
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions packages/react-server/core/renderMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -1073,13 +1073,21 @@ function getNonInternalConfigs() {

function getDeviceType(req) {
var md = new MobileDetect(req.get('user-agent'));
var types = [ 'phone', 'tablet' ];
for (var i = 0; i < types.length; i++) {
if (md[types[i]]()) {
return types[i];
}
}
return 'desktop';

// "mobile" is the union of "phone" and "tablet" _except_ for
// "unknown" mobile devices, which are _neither_ phone _nor_ tablet.
//
// http://hgoebl.github.io/mobile-detect.js/doc/MobileDetect.html#mobile
//
// :rage:
//
// We'll call them "phone" to avoid introducing a weird third device
// type that depends on this implementation quirk of mobile-detect.
//
if (md.tablet()) return "tablet";
if (md.phone ()) return "phone";
if (md.mobile()) return "phone";
return "desktop";
}

module.exports._testFunctions = {
Expand Down

0 comments on commit 5ced5ec

Please sign in to comment.