Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Classify "unknown" mobile devices as phones #955

Merged
merged 1 commit into from
Sep 29, 2017
Merged
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
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