Skip to content

Commit 5f1d1b7

Browse files
committed
Fix cart performance measurement to exclude debounce delays
- Move CartPerformance marker creation to start of updateQuantity operation - Replace measureFromEvent with measureFromMarker in finally block - Exclude 300ms debounce delay from user-action measurements - Prevent tab backgrounding from inflating P90 metrics - Align with Horizon theme's correct measurement approach This fixes unrealistic P90 times (17+ seconds) by measuring only actual network and DOM processing time, excluding artificial delays.
1 parent 1bad82a commit 5f1d1b7

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

assets/cart.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ class CartItems extends HTMLElement {
145145
}
146146

147147
updateQuantity(line, quantity, event, name, variantId) {
148+
const eventTarget = event.currentTarget instanceof CartRemoveButton ? 'clear' : 'change';
149+
const cartPerformanceUpdateMarker = CartPerformance.createStartingMarker(`${eventTarget}:user-action`);
150+
148151
this.enableLoading(line);
149152

150153
const body = JSON.stringify({
@@ -153,7 +156,6 @@ class CartItems extends HTMLElement {
153156
sections: this.getSectionsToRender().map((section) => section.section),
154157
sections_url: window.location.pathname,
155158
});
156-
const eventTarget = event.currentTarget instanceof CartRemoveButton ? 'clear' : 'change';
157159

158160
fetch(`${routes.cart_change_url}`, { ...fetchConfig(), ...{ body } })
159161
.then((response) => {
@@ -162,7 +164,7 @@ class CartItems extends HTMLElement {
162164
.then((state) => {
163165
const parsedState = JSON.parse(state);
164166

165-
CartPerformance.measure(`${eventTarget}:paint-updated-sections"`, () => {
167+
CartPerformance.measure(`${eventTarget}:paint-updated-sections`, () => {
166168
const quantityElement =
167169
document.getElementById(`Quantity-${line}`) || document.getElementById(`Drawer-quantity-${line}`);
168170
const items = document.querySelectorAll('.cart-item');
@@ -182,7 +184,8 @@ class CartItems extends HTMLElement {
182184

183185
this.getSectionsToRender().forEach((section) => {
184186
const elementToReplace =
185-
document.getElementById(section.id).querySelector(section.selector) || document.getElementById(section.id);
187+
document.getElementById(section.id).querySelector(section.selector) ||
188+
document.getElementById(section.id);
186189
elementToReplace.innerHTML = this.getSectionInnerHTML(
187190
parsedState.sections[section.section],
188191
section.selector
@@ -212,8 +215,6 @@ class CartItems extends HTMLElement {
212215
}
213216
});
214217

215-
CartPerformance.measureFromEvent(`${eventTarget}:user-action`, event);
216-
217218
publish(PUB_SUB_EVENTS.cartUpdate, { source: 'cart-items', cartData: parsedState, variantId: variantId });
218219
})
219220
.catch(() => {
@@ -223,6 +224,7 @@ class CartItems extends HTMLElement {
223224
})
224225
.finally(() => {
225226
this.disableLoading(line);
227+
CartPerformance.measureFromMarker(`${eventTarget}:user-action`, cartPerformanceUpdateMarker);
226228
});
227229
}
228230

@@ -284,8 +286,9 @@ if (!customElements.get('cart-note')) {
284286
'input',
285287
debounce((event) => {
286288
const body = JSON.stringify({ note: event.target.value });
287-
fetch(`${routes.cart_update_url}`, { ...fetchConfig(), ...{ body } })
288-
.then(() => CartPerformance.measureFromEvent('note-update:user-action', event));
289+
fetch(`${routes.cart_update_url}`, { ...fetchConfig(), ...{ body } }).then(() =>
290+
CartPerformance.measureFromEvent('note-update:user-action', event)
291+
);
289292
}, ON_CHANGE_DEBOUNCE_TIMER)
290293
);
291294
}

0 commit comments

Comments
 (0)