-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
ci: Add new metrics overhead app #7300
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
Merged
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,12 +12,10 @@ class CLS { | |
|
||
const observer = new PerformanceObserver((list) => { | ||
for (const entry of list.getEntries()) { | ||
if (!entry.hadRecentInput) { | ||
if (window.cumulativeLayoutShiftScore === undefined) { | ||
window.cumulativeLayoutShiftScore = entry.value; | ||
} else { | ||
window.cumulativeLayoutShiftScore += entry.value; | ||
} | ||
if (window.cumulativeLayoutShiftScore === undefined) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nevermind, I missed that you just rewrote this. |
||
window.cumulativeLayoutShiftScore = entry.value; | ||
} else if (!entry.hadRecentInput) { | ||
window.cumulativeLayoutShiftScore += entry.value; | ||
} | ||
} | ||
}); | ||
|
83 changes: 83 additions & 0 deletions
83
packages/overhead-metrics/test-apps/booking-app/index.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<!DOCTYPE html> | ||
<html lang="en" dir="ltr"> | ||
<head> | ||
<title>Demo Booking Engine</title> | ||
<meta http-equiv="content-type" content="text/html; charset=utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" /> | ||
<meta name="robots" content="noindex" /> | ||
|
||
<link rel="stylesheet" href="./style.css" /> | ||
</head> | ||
|
||
<body> | ||
<div class=""> | ||
<div class="header"> | ||
<h1>This is a test app.</h1> | ||
|
||
<div class="search-form"> | ||
<form name="search" id="search" data-form-state="0" action="" method="POST"> | ||
<div class="search-form-fields"> | ||
<div class="field"> | ||
<label for="check-in">Check-in</label> | ||
<input name="check-in" type="date" class="input" /> | ||
</div> | ||
|
||
<div class="field"> | ||
<label for="check-out">Check-out</label> | ||
<input name="check-out" type="date" class="input" /> | ||
</div> | ||
|
||
<div class="field"> | ||
<label for="adults">Number of persons</label> | ||
<select name="adults"> | ||
<option value="1">1</option> | ||
<option value="2" selected="">2</option> | ||
<option value="3">3</option> | ||
<option value="4">4</option> | ||
<option value="5">5</option> | ||
<option value="6">6</option> | ||
<option value="7">7</option> | ||
<option value="8">8</option> | ||
<option value="9">9</option> | ||
<option value="10">10</option> | ||
<option value="11">11</option> | ||
<option value="12">12</option> | ||
<option value="13">13</option> | ||
<option value="14">14</option> | ||
<option value="15">15</option> | ||
<option value="16">16</option> | ||
<option value="17">17</option> | ||
<option value="18">18</option> | ||
<option value="19">19</option> | ||
<option value="20">20</option> | ||
<option value="21">21</option> | ||
<option value="22">22</option> | ||
<option value="23">23</option> | ||
<option value="24">24</option> | ||
<option value="25">25</option> | ||
<option value="26">26</option> | ||
<option value="27">27</option> | ||
<option value="28">28</option> | ||
<option value="29">29</option> | ||
<option value="30">30</option> | ||
</select> | ||
</div> | ||
|
||
<div class="field"> | ||
<button type="submit">Update</button> | ||
</div> | ||
</div> | ||
</form> | ||
</div> | ||
|
||
<div> | ||
<form name="book" id="book" method="post"> | ||
<div class="result-list"></div> | ||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<script src="./main.js"></script> | ||
</body> | ||
</html> |
177 changes: 177 additions & 0 deletions
177
packages/overhead-metrics/test-apps/booking-app/main.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
(function () { | ||
const searchForm = document.querySelector('#search'); | ||
|
||
searchForm.addEventListener('submit', event => { | ||
event.preventDefault(); | ||
|
||
updateOffers(); | ||
}); | ||
|
||
const obs = new MutationObserver(function (mutations) { | ||
console.log(mutations); | ||
}); | ||
|
||
obs.observe(document.documentElement, { | ||
attributes: true, | ||
attributeOldValue: true, | ||
characterData: true, | ||
characterDataOldValue: true, | ||
childList: true, | ||
subtree: true, | ||
}); | ||
})(); | ||
|
||
function updateOffers() { | ||
const list = document.querySelector('.result-list'); | ||
|
||
// Clear out existing children | ||
for (let el of list.children) { | ||
list.removeChild(el); | ||
} | ||
|
||
// Add new children | ||
// Allow to define children count via URL ?count=100 | ||
const url = new URL(window.location.href); | ||
const count = parseInt(url.searchParams.get('count') || 50); | ||
for (let i = 0; i < count; i++) { | ||
const el = document.createElement('div'); | ||
el.classList.add('result'); | ||
el.innerHTML = generateResult(); | ||
|
||
const id = crypto.randomUUID(); | ||
el.setAttribute('id', id); | ||
|
||
addListeners(id, el); | ||
|
||
list.appendChild(el); | ||
} | ||
} | ||
|
||
function addListeners(id, el) { | ||
el.querySelector('[data-long-text-open]').addEventListener('click', event => { | ||
const parent = event.target.closest('.long-text'); | ||
parent.setAttribute('data-show-long', ''); | ||
}); | ||
el.querySelector('[data-long-text-close]').addEventListener('click', event => { | ||
const parent = event.target.closest('.long-text'); | ||
parent.removeAttribute('data-show-long'); | ||
}); | ||
|
||
// These are purposefully inefficient | ||
el.querySelector('[data-select]').addEventListener('click', () => { | ||
document.querySelectorAll('.result').forEach(result => { | ||
if (result.getAttribute('id') === id) { | ||
result.setAttribute('data-show-options', 'yes'); | ||
} else { | ||
result.setAttribute('data-show-options', 'no'); | ||
} | ||
}); | ||
|
||
// Do some more, extra expensive work | ||
document.querySelectorAll('.select__price').forEach(el => { | ||
el.setAttribute('js-is-checked', new Date().toISOString()); | ||
el.setAttribute('js-is-checked-2', new Date().toISOString()); | ||
el.setAttribute('js-is-checked-3', 'yes'); | ||
el.setAttribute('js-is-checked-4', 'yes'); | ||
el.setAttribute('js-is-checked-5', 'yes'); | ||
el.setAttribute('js-is-checked-6', 'yes'); | ||
}); | ||
document.querySelectorAll('.tag').forEach(el => el.setAttribute('js-is-checked', 'yes')); | ||
document.querySelectorAll('h3').forEach(el => el.setAttribute('js-is-checked', 'yes')); | ||
}); | ||
} | ||
|
||
const baseTitles = ['Cottage house', 'Cabin', 'Villa', 'House', 'Appartment', 'Cosy appartment']; | ||
const baseBeds = ['2', '2+2', '4+2', '6+2', '6+4']; | ||
const baseDescription = | ||
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'; | ||
|
||
function generateResult() { | ||
const title = `${getRandomItem(baseTitles)} ${Math.ceil(Math.random() * 20)}`; | ||
const beds = getRandomItem(baseBeds); | ||
const description = baseDescription | ||
.split(' ') | ||
.slice(Math.ceil(Math.random() * 10)) | ||
.join(' '); | ||
const price = 200 + Math.random() * 800; | ||
|
||
// Make short version of description | ||
const descriptionShort = description.slice(0, 200); | ||
const priceStr = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(price); | ||
|
||
const placeholders = { | ||
title, | ||
beds, | ||
description, | ||
descriptionShort, | ||
priceStr, | ||
}; | ||
|
||
return replacePlaceholders(template, placeholders); | ||
} | ||
|
||
function getRandomItem(list) { | ||
return list[Math.floor(Math.random() * list.length)]; | ||
} | ||
|
||
function replacePlaceholders(str, placeholders) { | ||
let replacedStr = str; | ||
Object.keys(placeholders).forEach(placeholder => { | ||
replacedStr = replacedStr.replaceAll(`{{${placeholder}}}`, placeholders[placeholder]); | ||
}); | ||
|
||
return replacedStr; | ||
} | ||
|
||
const template = `<figure class="result-image"> | ||
<img src="https://api.lorem.space/image/house?w=350&h=250" alt="{{title}}" data-image /> | ||
</figure> | ||
|
||
<div class="result-content"> | ||
<div> | ||
<h3>{{title}}</h3> | ||
|
||
<div class="tags"> | ||
<span class="tag">{{beds}}</span> | ||
</div> | ||
</div> | ||
|
||
<div class="long-text"> | ||
<div class="long-text__short"> | ||
{{descriptionShort}}<button type="button" data-long-text-open>... Read more</button> | ||
</div> | ||
|
||
<div class="long-text__long"> | ||
{{description}} | ||
<button type="button" data-long-text-close>Read less</button> | ||
</div> | ||
</div> | ||
|
||
<div class="select"> | ||
<button type="button" data-select> | ||
<div aria-hidden="true" class="icon">+</div> | ||
<div>Select</div> | ||
|
||
<div class="select__price"> | ||
<div class="price__amount">{{priceStr}}</div> | ||
<div class="price__quantity-label">/night</div> | ||
</div> | ||
</button> | ||
</div> | ||
|
||
<div class="options"> | ||
<div class="field"> | ||
<select> | ||
<option value="0">0 rooms</option> | ||
<option value="1">1 room</option> | ||
</select> | ||
</div> | ||
|
||
<div class="field"> | ||
<select> | ||
<option value="1">1 guest</option> | ||
<option value="2">2 guests</option> | ||
</select> | ||
</div> | ||
</div> | ||
</div>`; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we wait a little longer than 2000ms considering the timing inconsistencies we observed in #7266?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, true I guess! I'll extend it to 4000ms to be safe.