Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/loose-moments-itch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@lynx-js/web-elements": patch
---

perf: late evaluate document.font.ready
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,13 @@ export class XTextTruncation
if (!this.#componentConnected || this.#dom.matches('x-text>x-text')) return;
if (this.#scheduledTextLayout) return;
this.#scheduledTextLayout = true;
boostedQueueMicrotask(() => {
this.#layoutTextInner();
boostedQueueMicrotask(async () => {
await this.#layoutTextInner();
this.#startObservers();
queueMicrotask(() => {
this.#scheduledTextLayout = false;
});
this.#scheduledTextLayout = false;
});
}
#layoutTextInner() {
async #layoutTextInner() {
this.#inplaceEllipsisNode?.parentElement?.removeChild(
this.#inplaceEllipsisNode,
);
Expand All @@ -136,6 +134,7 @@ export class XTextTruncation
if (!this.#doExpensiveLineLayoutCalculation && isNaN(this.#maxLength)) {
return;
}
await document.fonts.ready;
const parentBondingRect = this.#getInnerBox().getBoundingClientRect();
this.#textMeasure = new TextRenderingMeasureTool(
this.#dom,
Expand Down Expand Up @@ -389,9 +388,7 @@ export class XTextTruncation
this.#handleEnableLayoutEvent(
this.#enableLayoutEvent,
);
document.fonts.ready.then(() => {
this.#handleAttributeChange();
});
this.#handleAttributeChange();
boostedQueueMicrotask(() => {
this.#sendLayoutEvent();
});
Expand Down
3 changes: 2 additions & 1 deletion packages/web-platform/web-tests/lighthouserc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { chromium } from '@playwright/test';
import cases from './tests/lighthouse.cases.js';

const port = process.env.PORT ?? 3080;
const isCI = !!process.env['CI'];
const config = {
ci: {
// Use the recommended Lighthouse CI preset
Expand Down Expand Up @@ -42,7 +43,7 @@ const config = {
// Configure throttling settings
throttling: {
rttMs: 0,
cpuSlowdownMultiplier: 2.5,
cpuSlowdownMultiplier: isCI ? 2.3 : 4,
requestLatencyMs: 0,
downloadThroughputKbps: 99999,
uploadThroughputKbps: 99999,
Expand Down
24 changes: 24 additions & 0 deletions packages/web-platform/web-tests/tests/lighthouse.cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,28 @@ export default [
],
},
},
{
'matchingUrlPattern':
'/web-element-tests/performance/x-text-with-font.html',
'assertions': {
'categories:performance': [
'error',
{
'minScore': 0.79,
},
],
'speed-index': [
'error',
{
'maxNumericValue': 550,
},
],
'total-blocking-time': [
'error',
{
'maxNumericValue': 500,
},
],
},
},
];
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
rel="stylesheet"
/>
<script type="module">
const top = document.createElement('div');
const htmlTokens = [];
for (let ii = 0; ii < 3000; ii++) {
htmlTokens.push('<x-text><raw-text text="hello lynx"></raw-text></x-text>');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<!DOCTYPE html>
<!-- Copyright 2023 The Lynx Authors. All rights reserved.
Licensed under the Apache License Version 2.0 that can be found in the
LICENSE file in the root directory of this source tree. -->
<html>
<head>
<meta charset="utf-8">
<title>web playground</title>
<meta content="yes" name="apple-mobile-web-app-capable">
<meta content="default" name="apple-mobile-web-app-status-bar-style">
<meta content="telephone=no" name="format-detection">
<meta content="portrait" name="screen-orientation">
<meta
content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no"
name="viewport"
>
<meta content="portrait" name="x5-orientation" />
<link
href="/web-elements.css"
rel="stylesheet"
/>
<link
href="/resources/font.css"
rel="stylesheet"
/>
<script type="module">
const htmlTokens = [];
for (let ii = 0; ii < 3000; ii++) {
htmlTokens.push('<x-text>hello lynx</x-text>');
}
document.body.innerHTML = htmlTokens.join('');
</script>
<style>
x-view {
height: 30px;
width: 100px;
}
x-view:nth-child(even) {
background-color: aqua;
}
x-text {
font-family: "Noto Sans SC";
}
</style>
</head>

<body>
<script src="/web-elements.js" defer></script>
</body>
</html>
Loading