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/rich-teams-melt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@lynx-js/web-elements": patch
---

fix: x-markdown inline view injection no longer queries light DOM children when the content attribute changes. Consumers must now pre-set `slot="{id}"` on the child element they want to project into `inlineview://{id}`.
Comment thread
Sherry-hue marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -1285,23 +1285,12 @@ export class XMarkdownAttributes {
const inlineId = img.getAttribute('data-inlineview');
if (inlineId) {
const id = inlineId;
const view = this.#dom.querySelector(`#${CSS.escape(id)}`);
if (view) {
const container = document.createElement('span');
container.className = 'md-inline-view';
const vAlign = (view as HTMLElement).getAttribute('vertical-align')
|| (view as HTMLElement).style.verticalAlign
|| '';
if (vAlign) {
(container.style as any).verticalAlign = vAlign;
}
const slot = document.createElement('slot');
const slotName = `md-inline-view-${id}`;
slot.name = slotName;
(view as HTMLElement).slot = slotName;
container.appendChild(slot);
img.replaceWith(container);
}
const container = document.createElement('span');
container.className = 'md-inline-view';
const slot = document.createElement('slot');
slot.name = `md-inline-view-${id}`;
container.appendChild(slot);
img.replaceWith(container);
}
}
} catch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
<script src="/main.js" defer></script>
<x-view class="page">
<x-markdown id="markdown" style="width: 300px">
<x-view id="content-view" class="content"></x-view>
<x-view
id="content-view"
slot="md-inline-view-content-view"
class="content"
></x-view>
</x-markdown>
</x-view>
<script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<x-markdown id="markdown" style="width: 300px">
<x-view
id="badge"
vertical-align="middle"
slot="md-inline-view-badge"
style="display: inline-block; width: 10px; height: 10px; background: rgb(255, 0, 0)"
></x-view>
</x-markdown>
Expand Down
16 changes: 9 additions & 7 deletions packages/web-platform/web-elements/tests/x-markdown.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { test, expect } from '@lynx-js/playwright-fixtures';
import type { Page } from '@playwright/test';

Expand Down Expand Up @@ -94,7 +94,7 @@
await goto(page, 'x-markdown/basic');
const markdown = page.locator('x-markdown');

await expect(markdown.locator('h1')).toHaveText('Title');

Check failure on line 97 in packages/web-platform/web-elements/tests/x-markdown.spec.ts

View workflow job for this annotation

GitHub Actions / Playwright Web Elements Test (2/2) / check

[chromium] › tests/x-markdown.spec.ts:93:3 › x-markdown › should render basic markdown

3) [chromium] › tests/x-markdown.spec.ts:93:3 › x-markdown › should render basic markdown ──────── Error: expect(locator).toHaveText(expected) failed Locator: locator('x-markdown').locator('h1') Expected: "Title" Timeout: 5000ms Error: element(s) not found Call log: - Expect "toHaveText" with timeout 5000ms - waiting for locator('x-markdown').locator('h1') 95 | const markdown = page.locator('x-markdown'); 96 | > 97 | await expect(markdown.locator('h1')).toHaveText('Title'); | ^ 98 | await expect(markdown.locator('strong')).toHaveText('bold'); 99 | await expect(markdown.locator('em')).toHaveText('italic'); 100 | await expect(markdown.locator('li')).toHaveCount(2); at /__w/lynx-stack/lynx-stack/packages/web-platform/web-elements/tests/x-markdown.spec.ts:97:42

Check failure on line 97 in packages/web-platform/web-elements/tests/x-markdown.spec.ts

View workflow job for this annotation

GitHub Actions / Playwright Web Elements Test (1/2) / check

[webkit] › tests/x-markdown.spec.ts:93:3 › x-markdown › should render basic markdown

3) [webkit] › tests/x-markdown.spec.ts:93:3 › x-markdown › should render basic markdown ────────── Error: expect(locator).toHaveText(expected) failed Locator: locator('x-markdown').locator('h1') Expected: "Title" Timeout: 5000ms Error: element(s) not found Call log: - Expect "toHaveText" with timeout 5000ms - waiting for locator('x-markdown').locator('h1') 95 | const markdown = page.locator('x-markdown'); 96 | > 97 | await expect(markdown.locator('h1')).toHaveText('Title'); | ^ 98 | await expect(markdown.locator('strong')).toHaveText('bold'); 99 | await expect(markdown.locator('em')).toHaveText('italic'); 100 | await expect(markdown.locator('li')).toHaveCount(2); at /__w/lynx-stack/lynx-stack/packages/web-platform/web-elements/tests/x-markdown.spec.ts:97:42
await expect(markdown.locator('strong')).toHaveText('bold');
await expect(markdown.locator('em')).toHaveText('italic');
await expect(markdown.locator('li')).toHaveCount(2);
Expand All @@ -104,7 +104,7 @@
test('should apply markdown-style updates', async ({ page }) => {
await goto(page, 'x-markdown/style');
const markdown = page.locator('x-markdown');
await page.waitForFunction(() => {

Check failure on line 107 in packages/web-platform/web-elements/tests/x-markdown.spec.ts

View workflow job for this annotation

GitHub Actions / Playwright Web Elements Test (1/2) / check

[webkit] › tests/x-markdown.spec.ts:104:3 › x-markdown › should apply markdown-style updates

4) [webkit] › tests/x-markdown.spec.ts:104:3 › x-markdown › should apply markdown-style updates ── Error: page.waitForFunction: Test timeout of 30000ms exceeded. 105 | await goto(page, 'x-markdown/style'); 106 | const markdown = page.locator('x-markdown'); > 107 | await page.waitForFunction(() => { | ^ 108 | const element = document.querySelector('x-markdown'); 109 | return element?.shadowRoot?.querySelector('a')?.textContent === 'link'; 110 | }); at /__w/lynx-stack/lynx-stack/packages/web-platform/web-elements/tests/x-markdown.spec.ts:107:16
const element = document.querySelector('x-markdown');
return element?.shadowRoot?.querySelector('a')?.textContent === 'link';
});
Expand Down Expand Up @@ -140,7 +140,7 @@
});

expect(propertyValue).toEqual({ link: { color: '00ff00' } });
await expect(link).toHaveCSS('color', 'rgb(0, 255, 0)');

Check failure on line 143 in packages/web-platform/web-elements/tests/x-markdown.spec.ts

View workflow job for this annotation

GitHub Actions / Playwright Web Elements Test (1/2) / check

[webkit] › tests/x-markdown.spec.ts:132:3 › x-markdown › should support markdown-style property updates

5) [webkit] › tests/x-markdown.spec.ts:132:3 › x-markdown › should support markdown-style property updates Error: expect(locator).toHaveCSS(expected) failed Locator: locator('x-markdown').locator('a') Expected: "rgb(0, 255, 0)" Timeout: 5000ms Error: element(s) not found Call log: - Expect "toHaveCSS" with timeout 5000ms - waiting for locator('x-markdown').locator('a') 141 | 142 | expect(propertyValue).toEqual({ link: { color: '00ff00' } }); > 143 | await expect(link).toHaveCSS('color', 'rgb(0, 255, 0)'); | ^ 144 | await expect(markdown).toHaveAttribute( 145 | 'markdown-style', 146 | JSON.stringify({ link: { color: '00ff00' } }), at /__w/lynx-stack/lynx-stack/packages/web-platform/web-elements/tests/x-markdown.spec.ts:143:24
await expect(markdown).toHaveAttribute(
'markdown-style',
JSON.stringify({ link: { color: '00ff00' } }),
Expand All @@ -152,7 +152,7 @@
const markdown = page.locator('x-markdown');

const image = markdown.locator('img');
await expect(image).toHaveAttribute(

Check failure on line 155 in packages/web-platform/web-elements/tests/x-markdown.spec.ts

View workflow job for this annotation

GitHub Actions / Playwright Web Elements Test (1/2) / check

[webkit] › tests/x-markdown.spec.ts:150:3 › x-markdown › should render image

6) [webkit] › tests/x-markdown.spec.ts:150:3 › x-markdown › should render image ────────────────── Error: expect(locator).toHaveAttribute(expected) failed Locator: locator('x-markdown').locator('img') Expected: "/tests/fixtures/resources/firefox-logo.png" Timeout: 5000ms Error: element(s) not found Call log: - Expect "toHaveAttribute" with timeout 5000ms - waiting for locator('x-markdown').locator('img') 153 | 154 | const image = markdown.locator('img'); > 155 | await expect(image).toHaveAttribute( | ^ 156 | 'src', 157 | '/tests/fixtures/resources/firefox-logo.png', 158 | ); at /__w/lynx-stack/lynx-stack/packages/web-platform/web-elements/tests/x-markdown.spec.ts:155:25
'src',
'/tests/fixtures/resources/firefox-logo.png',
);
Expand All @@ -165,7 +165,7 @@
await markdown.evaluate((el) => {
el.setAttribute('content', '# Updated');
});
await expect(markdown.locator('h1')).toHaveText('Updated');

Check failure on line 168 in packages/web-platform/web-elements/tests/x-markdown.spec.ts

View workflow job for this annotation

GitHub Actions / Playwright Web Elements Test (1/2) / check

[webkit] › tests/x-markdown.spec.ts:161:3 › x-markdown › should update content on attribute change

7) [webkit] › tests/x-markdown.spec.ts:161:3 › x-markdown › should update content on attribute change Error: expect(locator).toHaveText(expected) failed Locator: locator('x-markdown').locator('h1') Expected: "Updated" Timeout: 5000ms Error: element(s) not found Call log: - Expect "toHaveText" with timeout 5000ms - waiting for locator('x-markdown').locator('h1') 166 | el.setAttribute('content', '# Updated'); 167 | }); > 168 | await expect(markdown.locator('h1')).toHaveText('Updated'); | ^ 169 | }); 170 | 171 | test('should only allow span and p html tags in markdown content', async ({ page }) => { at /__w/lynx-stack/lynx-stack/packages/web-platform/web-elements/tests/x-markdown.spec.ts:168:42
});

test('should only allow span and p html tags in markdown content', async ({ page }) => {
Expand All @@ -173,7 +173,7 @@
const markdown = page.locator('x-markdown');

const span = markdown.locator('span.mark-red');
await expect(span).toHaveText('World');

Check failure on line 176 in packages/web-platform/web-elements/tests/x-markdown.spec.ts

View workflow job for this annotation

GitHub Actions / Playwright Web Elements Test (1/2) / check

[webkit] › tests/x-markdown.spec.ts:171:3 › x-markdown › should only allow span and p html tags in markdown content

8) [webkit] › tests/x-markdown.spec.ts:171:3 › x-markdown › should only allow span and p html tags in markdown content Error: expect(locator).toHaveText(expected) failed Locator: locator('x-markdown').locator('span.mark-red') Expected: "World" Timeout: 5000ms Error: element(s) not found Call log: - Expect "toHaveText" with timeout 5000ms - waiting for locator('x-markdown').locator('span.mark-red') 174 | 175 | const span = markdown.locator('span.mark-red'); > 176 | await expect(span).toHaveText('World'); | ^ 177 | await expect(span).not.toHaveAttribute('style', /.+/); 178 | await expect(span).not.toHaveAttribute('onclick', /.+/); 179 | at /__w/lynx-stack/lynx-stack/packages/web-platform/web-elements/tests/x-markdown.spec.ts:176:24
await expect(span).not.toHaveAttribute('style', /.+/);
await expect(span).not.toHaveAttribute('onclick', /.+/);

Expand All @@ -191,7 +191,7 @@
await goto(page, 'x-markdown/events');
const markdown = page.locator('x-markdown');

await markdown.locator('a').click();

Check failure on line 194 in packages/web-platform/web-elements/tests/x-markdown.spec.ts

View workflow job for this annotation

GitHub Actions / Playwright Web Elements Test (1/2) / check

[webkit] › tests/x-markdown.spec.ts:190:3 › x-markdown › should fire bindlink and bindimageTap events

9) [webkit] › tests/x-markdown.spec.ts:190:3 › x-markdown › should fire bindlink and bindimageTap events Error: locator.click: Test timeout of 30000ms exceeded. Call log: - waiting for locator('x-markdown').locator('a') 192 | const markdown = page.locator('x-markdown'); 193 | > 194 | await markdown.locator('a').click(); | ^ 195 | await page.waitForFunction(() => (window as any)._bindlink_detail !== null); 196 | const linkDetail = await page.evaluate(() => 197 | (window as any)._bindlink_detail at /__w/lynx-stack/lynx-stack/packages/web-platform/web-elements/tests/x-markdown.spec.ts:194:33
await page.waitForFunction(() => (window as any)._bindlink_detail !== null);
const linkDetail = await page.evaluate(() =>
(window as any)._bindlink_detail
Expand Down Expand Up @@ -617,22 +617,24 @@
]);
});

test('should inject inline view and keep vertical-align', async ({ page }) => {
test('should inject inline view via pre-set slot', async ({ page }) => {
await goto(page, 'x-markdown/inlineview');
await page.waitForFunction(() => {
const el = document.querySelector('x-markdown');
const root = el && (el as any).shadowRoot;
return !!root && !!root.querySelector('.md-inline-view');
});
const va = await page.evaluate(() => {
const projected = await page.evaluate(() => {
const el = document.querySelector('x-markdown')!;
const root = el.shadowRoot as ShadowRoot;
const inline = root.querySelector('.md-inline-view') as
| HTMLElement
| null;
return inline ? getComputedStyle(inline).verticalAlign : '';
const slot = root.querySelector(
'.md-inline-view slot',
) as HTMLSlotElement | null;
return slot?.assignedElements().some((node) =>
(node as HTMLElement).id === 'badge'
) ?? false;
});
expect(va).toBe('middle');
expect(projected).toBe(true);
});

test('should apply class styles to inline view', async ({ page }) => {
Expand Down
Loading