Skip to content
This repository has been archived by the owner on Aug 1, 2024. It is now read-only.

Commit

Permalink
RELNOTES[NEW]: Provide goog.labs.userAgent.USE_CLIENT_HINTS_OVERRIDE …
Browse files Browse the repository at this point in the history
…as a runtime-override mechanism for overriding USE_CLIENT_HINTS in production builds.

PiperOrigin-RevId: 398765743
Change-Id: I48aec9a4b0e70835867d6344813fcb4653cf8f95
  • Loading branch information
shicks authored and copybara-github committed Sep 24, 2021
1 parent 83aa32c commit 41e7935
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion closure/goog/labs/useragent/useragent.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,30 @@

goog.module('goog.labs.userAgent');

/**
* @define {string} Optional runtime override for the USE_CLIENT_HINTS flag.
* If this is set (for example, to 'foo.bar') then any value of USE_CLIENT_HINTS
* will be overridden by `globalThis.foo.bar` if it is non-null.
* This flag will be removed in December 2021.
*/
const USE_CLIENT_HINTS_OVERRIDE =
goog.define('goog.labs.userAgent.USE_CLIENT_HINTS_OVERRIDE', '');

/**
* @define {boolean} If true, use navigator.userAgentData
* TODO(user) Flip flag in 2021/12.
*/
const USE_CLIENT_HINTS =
goog.define('goog.labs.userAgent.USE_CLIENT_HINTS', false);
exports.USE_CLIENT_HINTS = USE_CLIENT_HINTS;

// TODO(user): Replace the IIFE with a simple null-coalescing operator.
// NOTE: This can't be done with a helper function, or else we risk an inlining
// back-off causing a huge code size regression if a non-inlined helper function
// prevents the optimizer from detecting the (possibly large) dead code paths.
/** @const {boolean} */
exports.USE_CLIENT_HINTS = (() => {
const override = USE_CLIENT_HINTS_OVERRIDE ?
goog.getObjectByName(USE_CLIENT_HINTS_OVERRIDE) :
null;
return override != null ? override : USE_CLIENT_HINTS;
})();

0 comments on commit 41e7935

Please # to comment.