Skip to content

Commit

Permalink
Only import sf debug tools if sfdebug url param is present (#1415)
Browse files Browse the repository at this point in the history
* Only import sf debug tools if sfdebug url param is present

* Changeset

* Fix typescript error
  • Loading branch information
emma-imber authored Jun 17, 2024
1 parent 9cdd4e6 commit 500a157
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/loud-cameras-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@guardian/commercial': minor
---

Only import spacefinder debug tools when the sfdebug url param is present
5 changes: 0 additions & 5 deletions src/insert/spacefinder/spacefinder-debug-tools.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { log } from '@guardian/libs';
import { getUrlVars } from 'utils/url';
import type {
SpacefinderExclusions,
SpacefinderItem,
Expand All @@ -8,8 +7,6 @@ import type {
} from './spacefinder';
import logo from './spacefinder-logo.svg';

const enableDebug = !!getUrlVars().sfdebug;

const isCurrentPass = (pass: SpacefinderPass) => {
const sfdebugPass = document.querySelector<HTMLInputElement>(
'input[name="sfdebug-pass"]:checked',
Expand Down Expand Up @@ -418,8 +415,6 @@ const init = (
rules: SpacefinderRules,
pass: SpacefinderPass,
): void => {
if (!enableDebug) return;

addDebugPanel();
annotate(exclusions, winners, rules, pass);
addPassToDebugPanel(pass);
Expand Down
11 changes: 9 additions & 2 deletions src/insert/spacefinder/spacefinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { log } from '@guardian/libs';
import { memoize } from 'lodash-es';
import fastdom from 'utils/fastdom-promise';
import { init as initSpacefinderDebugger } from './spacefinder-debug-tools';
import { getUrlVars } from 'utils/url';

type RuleSpacing = {
/**
Expand Down Expand Up @@ -591,7 +591,14 @@ const findSpace = async (
const measurements = await getMeasurements(rules, candidates);
const winners = enforceRules(measurements, rules, exclusions);

initSpacefinderDebugger(exclusions, winners, rules, options.pass);
const enableDebug = !!getUrlVars().sfdebug;

if (enableDebug) {
const pass = options.pass;
void import('./spacefinder-debug-tools').then(({ init }) => {
init(exclusions, winners, rules, pass);
});
}

window.performance.mark('commercial:spacefinder:findSpace:end');

Expand Down

0 comments on commit 500a157

Please sign in to comment.