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
9 changes: 9 additions & 0 deletions .changeset/shiny-eyes-follow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@lynx-js/web-elements": patch
---

fix: x-list should observe property list-type change.

Before this commit, list-type only works when it was first assigned.

use `requestAnimationFrame` instead of `queueMicrotask` to layoutListItem, this is because it may cause crashes in webkit.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import {
} from '@lynx-js/web-elements-reactive';
import type { XList } from './XList.js';

const WATERFALL_SLOT = 'waterfall-slot';

export class XListAttributes
implements InstanceType<AttributeReactiveClass<typeof HTMLElement>>
{
Expand Down
22 changes: 17 additions & 5 deletions packages/web-platform/web-elements/src/XList/XListWaterfall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
// LICENSE file in the root directory of this source tree.
*/
import {
boostedQueueMicrotask,
genDomGetter,
registerAttributeHandler,
type AttributeReactiveClass,
} from '@lynx-js/web-elements-reactive';
import type { XList } from './XList.js';
Expand All @@ -16,7 +16,7 @@ const WATERFALL_STYLE = 'waterfall-style';
export class XListWaterfall
implements InstanceType<AttributeReactiveClass<typeof HTMLElement>>
{
static observedAttributes = [];
static observedAttributes = ['list-type'];

#dom: XList;
#getListContainer = genDomGetter(() => this.#dom.shadowRoot!, '#content');
Expand Down Expand Up @@ -182,7 +182,7 @@ export class XListWaterfall
this.#resizeObserver = new ResizeObserver(() => {
// may cause: Resizeobserver loop completed with undelivered notifications
// https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver#observation_errors
boostedQueueMicrotask(() => {
requestAnimationFrame(() => {
Comment thread
PupilTong marked this conversation as resolved.
this.#layoutListItem(
spanCount,
isScrollVertical,
Expand All @@ -194,8 +194,9 @@ export class XListWaterfall
});
};

connectedCallback() {
if (this.#dom.getAttribute('list-type') === 'waterfall') {
@registerAttributeHandler('list-type', true)
#handlerListType(newVal: string | null) {
if (newVal === 'waterfall') {
const spanCount = parseFloat(
this.#dom.getAttribute('span-count')
|| this.#dom.getAttribute('column-count')
Expand Down Expand Up @@ -227,6 +228,17 @@ export class XListWaterfall
childList: true,
});
}
} else {
this.#resizeObserver?.disconnect();
this.#resizeObserver = undefined;
this.#childrenObserver?.disconnect();
this.#childrenObserver = undefined;
for (let i = 0; i < this.#dom.children.length; i++) {
const listItem = this.#dom.children[i] as HTMLElement;
listItem.removeAttribute('slot');
}
this.#dom.shadowRoot?.querySelector(`slot[name=${WATERFALL_SLOT}]`)
?.remove();
}
}
}
1 change: 1 addition & 0 deletions packages/web-platform/web-elements/src/XList/x-list.css
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ list-item {
display: none;
content-visibility: auto;
flex: 0 0 auto !important;
position: static;
}

x-list > list-item, x-list > lynx-wrapper > list-item {
Expand Down
28 changes: 28 additions & 0 deletions packages/web-platform/web-tests/tests/web-elements.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
ReturnType<typeof expect<Page>>['toHaveScreenshot']
>[0],
) => {
await expect(page).toHaveScreenshot([`${caseName}`, `${subcaseName}.png`], {

Check failure on line 23 in packages/web-platform/web-tests/tests/web-elements.spec.ts

View workflow job for this annotation

GitHub Actions / playwright-linux / check

[chromium] › tests/web-elements.spec.ts:2867:5 › web-elements test suite › x-refresh-view › x-refresh-view/pull

8) [chromium] › tests/web-elements.spec.ts:2867:5 › web-elements test suite › x-refresh-view › x-refresh-view/pull Error: expect(page).toHaveScreenshot(expected) 188500 pixels (ratio 0.66 of all image pixels) are different. Expected: /home/runner/_work/lynx-stack/lynx-stack/packages/web-platform/web-tests/tests/web-elements.spec.ts-snapshots/x-refresh-view/pull/initial-chromium-linux.png Received: /home/runner/_work/lynx-stack/lynx-stack/packages/web-platform/web-tests/test-results/web-elements-web-elements--01c68-sh-view-x-refresh-view-pull-chromium/x-refresh-view/pull/initial-actual.png Diff: /home/runner/_work/lynx-stack/lynx-stack/packages/web-platform/web-tests/test-results/web-elements-web-elements--01c68-sh-view-x-refresh-view-pull-chromium/x-refresh-view/pull/initial-diff.png Call log: - expect.toHaveScreenshot(x-refresh-view/pull/initial.png) with timeout 5000ms - verifying given screenshot expectation - taking page screenshot - waiting for fonts to load... - fonts loaded - 188500 pixels (ratio 0.66 of all image pixels) are different. - waiting 100ms before taking screenshot - taking page screenshot - waiting for fonts to load... - fonts loaded - captured a stable screenshot - 188500 pixels (ratio 0.66 of all image pixels) are different. 21 | >[0], 22 | ) => { > 23 | await expect(page).toHaveScreenshot([`${caseName}`, `${subcaseName}.png`], { | ^ 24 | maxDiffPixelRatio: 0, 25 | fullPage: true, 26 | animations: 'allow', at diffScreenShot (/home/runner/_work/lynx-stack/lynx-stack/packages/web-platform/web-tests/tests/web-elements.spec.ts:23:22) at /home/runner/_work/lynx-stack/lynx-stack/packages/web-platform/web-tests/tests/web-elements.spec.ts:2873:13
maxDiffPixelRatio: 0,
fullPage: true,
animations: 'allow',
Expand Down Expand Up @@ -2351,6 +2351,34 @@
await gotoWebComponentPage(page, title);
await diffScreenShot(page, title, 'index');
});
test('list-type-change', async ({ page }) => {
await gotoWebComponentPage(page, 'x-list/basic-waterfall');
await diffScreenShot(page, 'x-list/list-type-change', 'index');
await page.evaluate(() => {
document.querySelector('x-list')?.setAttribute(
'list-type',
'single',
);
});
await wait(100);
await diffScreenShot(page, 'x-list/list-type-change', 'single');
await page.evaluate(() => {
document.querySelector('x-list')?.setAttribute(
'list-type',
'flow',
);
});
await wait(100);
await diffScreenShot(page, 'x-list/list-type-change', 'flow');
await page.evaluate(() => {
document.querySelector('x-list')?.setAttribute(
'list-type',
'waterfall',
);
});
await wait(100);
await diffScreenShot(page, 'x-list/list-type-change', 'waterfall');
});
});
test.describe('x-input', () => {
test('placeholder', async ({ page }, { titlePath }) => {
Expand Down Expand Up @@ -4093,7 +4121,7 @@
await page.locator('#play').click();
await wait(100);
// expect(loading).toBe(true);
expect(success).toBe(true);

Check failure on line 4124 in packages/web-platform/web-tests/tests/web-elements.spec.ts

View workflow job for this annotation

GitHub Actions / playwright-linux / check

[chromium] › tests/web-elements.spec.ts:4098:5 › web-elements test suite › x-audio-tt › event-srcloadingstatechanged

9) [chromium] › tests/web-elements.spec.ts:4098:5 › web-elements test suite › x-audio-tt › event-srcloadingstatechanged Error: expect(received).toBe(expected) // Object.is equality Expected: true Received: false 4122 | await wait(100); 4123 | // expect(loading).toBe(true); > 4124 | expect(success).toBe(true); | ^ 4125 | }); 4126 | 4127 | test('event-playbackstatechanged', async ({ page }, { titlePath }) => { at /home/runner/_work/lynx-stack/lynx-stack/packages/web-platform/web-tests/tests/web-elements.spec.ts:4124:23
});

test('event-playbackstatechanged', async ({ page }, { titlePath }) => {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading