From 220db3ead93eb52d3cae38646ad0f87194926c50 Mon Sep 17 00:00:00 2001 From: Bo Borgerson Date: Fri, 29 Sep 2017 10:45:09 -0700 Subject: [PATCH] Classify "unknown" mobile devices as phones This deals with an edge case of mobile-detect. See commentary. --- .../react-server/core/renderMiddleware.js | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/packages/react-server/core/renderMiddleware.js b/packages/react-server/core/renderMiddleware.js index 2de4ac588..7507339d8 100644 --- a/packages/react-server/core/renderMiddleware.js +++ b/packages/react-server/core/renderMiddleware.js @@ -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 = {