Skip to content

Commit 53b5f19

Browse files
committed
Add fallback for log function in Embed Optimizer and Image Prioritizer
Signed-off-by: Shyamsundar Gadde <[email protected]>
1 parent 9c05bde commit 53b5f19

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

plugins/embed-optimizer/detect.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ const loadedElementContentRects = new Map();
3232
* @type {InitializeCallback}
3333
* @param {InitializeArgs} args Args.
3434
*/
35-
export async function initialize( { log } ) {
35+
export async function initialize( { log: _log } ) {
36+
// eslint-disable-next-line no-console
37+
const log = _log || console.log; // TODO: Remove once Optimization Detective likely updated, or when strict version requirement added in od_init action.
38+
3639
/** @type NodeListOf<HTMLDivElement> */
3740
const embedWrappers = document.querySelectorAll(
3841
'.wp-block-embed > .wp-block-embed__wrapper[data-od-xpath]'
@@ -52,11 +55,17 @@ export async function initialize( { log } ) {
5255
* @param {FinalizeArgs} args Args.
5356
*/
5457
export async function finalize( {
55-
log,
56-
error,
58+
log: _log,
59+
error: _error,
5760
getElementData,
5861
extendElementData,
5962
} ) {
63+
/* eslint-disable no-console */
64+
// TODO: Remove once Optimization Detective likely updated, or when strict version requirement added in od_init action.
65+
const log = _log || console.log;
66+
const error = _error || console.error;
67+
/* eslint-enable no-console */
68+
6069
for ( const [ xpath, domRect ] of loadedElementContentRects.entries() ) {
6170
try {
6271
extendElementData( xpath, {

plugins/image-prioritizer/detect.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ const externalBackgroundImages = [];
4040
* @type {InitializeCallback}
4141
* @param {InitializeArgs} args Args.
4242
*/
43-
export async function initialize( { log, onLCP } ) {
43+
export async function initialize( { log: _log, onLCP } ) {
44+
// eslint-disable-next-line no-console
45+
const log = _log || console.log; // TODO: Remove once Optimization Detective likely updated, or when strict version requirement added in od_init action.
46+
4447
onLCP(
4548
( metric ) => {
4649
handleLCPMetric( metric, log );
@@ -137,7 +140,10 @@ function handleLCPMetric( metric, log ) {
137140
* @type {FinalizeCallback}
138141
* @param {FinalizeArgs} args Args.
139142
*/
140-
export async function finalize( { extendRootData, log } ) {
143+
export async function finalize( { extendRootData, log: _log } ) {
144+
// eslint-disable-next-line no-console
145+
const log = _log || console.log; // TODO: Remove once Optimization Detective likely updated, or when strict version requirement added in od_init action.
146+
141147
if ( externalBackgroundImages.length === 0 ) {
142148
return;
143149
}

0 commit comments

Comments
 (0)