Skip to content

AI-native design editor. Open-source Figma alternative.

perf: keep revisited pages' layout and lint, and build only shown Lint rows (#1287)

Danila Poyarkov352332c5da0a
diff --git a/changes/1287/performance.md b/changes/1287/performance.md
new file mode 100644
index 000000000..a396d1349
--- /dev/null
+++ b/changes/1287/performance.md
@@ -0,0 +1 @@
+- Switching back to a page keeps its layout and shows its design check right away when nothing on it changed, and the Lint panel builds only the rows it shows.
diff --git a/packages/core/src/editor/pages.ts b/packages/core/src/editor/pages.ts
index 0504067ff..3cf364676 100644
--- a/packages/core/src/editor/pages.ts
+++ b/packages/core/src/editor/pages.ts
@@ -19,6 +19,7 @@ import { collectGraphFontRequirements } from '#core/text/requirements'
import { missingGraphFontScripts } from '#core/text/resolved-requirements'
import { createPageViewportStore } from './page-viewports'
+import { createPageLayouts } from './pages/layouts'
import type { EditorContext } from './types'
export interface PageSwitchProgress {
@@ -83,6 +84,7 @@ export function componentSetPages(graph: SceneGraph, pageId: string): string[] {
export function createPageActions(ctx: EditorContext, drawing?: PageDrawing) {
const pageViewportStore = createPageViewportStore(ctx)
+ const pageLayouts = createPageLayouts(ctx)
function syncPageColor() {
ctx.state.pageColor = getPageColor(ctx.graph.getNode(ctx.state.currentPageId))
}
@@ -223,9 +225,11 @@ export function createPageActions(ctx: EditorContext, drawing?: PageDrawing) {
await resolvePageFonts(pageId, page.name, options)
throwIfAborted(options.signal)
if (generation !== pageSwitchGeneration) return null
- if (ctx.getRenderer() || populated) {
+ // A page visited before keeps the layout it got then, unless something it depends on changed.
+ if ((ctx.getRenderer() || populated) && !pageLayouts.isCurrent(pageId)) {
options.onProgress?.({ phase: 'layout', detail: page.name })
ctx.graph.applyDerivedLayoutDuring(() => computeAllLayouts(ctx.graph, pageId))
+ pageLayouts.record(pageId)
}
throwIfAborted(options.signal)
if (generation !== pageSwitchGeneration) return null
diff --git a/packages/core/src/editor/pages/layouts.ts b/packages/core/src/editor/pages/layouts.ts
new file mode 100644
index 000000000..90bb538f4
--- /dev/null
+++ b/packages/core/src/editor/pages/layouts.ts
@@ -0,0 +1,56 @@
+import type { EditorContext } from '#core/editor/types'
+import { getTextMeasurer, type TextMeasurer } from '#core/layout/text-measurement'
+import { fontManager } from '#core/text/fonts'
+
+/** What sized a page's text when it was laid out. */
+interface TextBasis {
+ fontGeneration: number
+ measurer: TextMeasurer | null
+}
+
+function currentTextBasis(): TextBasis {
+ return { fontGeneration: fontManager.generation(), measurer: getTextMeasurer() }
+}
+
+/**
+ * Which pages are laid out as they are now, so switching back to one does not lay it out again.
+ * A page needs layout again once a layer on it changes, other than by layout itself, or once
+ * the fonts or text measurer that size its text change. Layout reads variables only through the
+ * layers they are bound to, whose updates count as changes.
+ */
+export function createPageLayouts(ctx: Pick<EditorContext, 'graph' | 'onEditorEvent'>) {
+ const laidOut = new Map<string, TextBasis>()
+
+ function changed(nodeId: string | null | undefined) {
+ if (!nodeId || ctx.graph.isApplyingLayout) return
+ const pageId = ctx.graph.pageOf(nodeId)
+ if (pageId) laidOut.delete(pageId)
+ }
+
+ ctx.onEditorEvent('node:created', (node) => changed(node.id))
+ ctx.onEditorEvent('node:updated', (id) => changed(id))
+ ctx.onEditorEvent('node:deleted', (_id, parentId) => changed(parentId))
+ ctx.onEditorEvent('node:reparented', (_id, oldParentId, newParentId) => {
+ changed(oldParentId)
+ changed(newParentId)
+ })
+ ctx.onEditorEvent('node:reordered', (_id, parentId, _index, previousParentId) => {
+ changed(parentId)
+ changed(previousParentId)
+ })
+ ctx.onEditorEvent('graph:replaced', () => laidOut.clear())
+
+ /** Whether `pageId` is laid out as its layers, fonts and text measurer are now. */
+ function isCurrent(pageId: string): boolean {
+ const last = laidOut.get(pageId)
+ const now = currentTextBasis()
+ return last?.fontGeneration === now.fontGeneration && last.measurer === now.measurer
+ }
+
+ /** Call once `pageId` has been laid out. */
+ function record(pageId: string) {
+ laidOut.set(pageId, currentTextBasis())
+ }
+
+ return { isCurrent, record }
+}
diff --git a/packages/core/tests/editor/pages/layouts.test.ts b/packages/core/tests/editor/pages/layouts.test.ts
new file mode 100644
index 000000000..a911286a6
--- /dev/null
+++ b/packages/core/tests/editor/pages/layouts.test.ts
@@ -0,0 +1,70 @@
+import { afterEach, describe, expect, test } from 'bun:test'
+
+import { createEditor } from '@open-pencil/core/editor'
+import { SceneGraph } from '@open-pencil/scene-graph'
+
+import { createPageLayouts } from '#core/editor/pages/layouts'
+import { getTextMeasurer, setTextMeasurer } from '#core/layout/text-measurement'
+
+const initialMeasurer = getTextMeasurer()
+afterEach(() => setTextMeasurer(initialMeasurer))
+
+/** An editor with two pages, each holding a card, and a page laid out on the first. */
+function laidOutFirstPage() {
+ const editor = createEditor()
+ const first = editor.state.currentPageId
+ const second = editor.graph.addPage('Second').id
+ const card = editor.graph.createNode('FRAME', first, { name: 'Card', width: 100, height: 50 })
+ const otherCard = editor.graph.createNode('FRAME', second, { name: 'Card', width: 100 })
+ const layouts = createPageLayouts(editor)
+ layouts.record(first)
+ return { editor, first, card, otherCard, layouts }
+}
+
+describe('a page laid out before', () => {
+ test('stays laid out until a layer on it changes', () => {
+ const { editor, first, card, layouts } = laidOutFirstPage()
+ expect(layouts.isCurrent(first)).toBe(true)
+
+ editor.graph.updateNode(card.id, { width: 120 })
+
+ expect(layouts.isCurrent(first)).toBe(false)
+ editor.dispose()
+ })
+
+ test("stays laid out through layout's own writes and edits on other pages", () => {
+ const { editor, first, card, otherCard, layouts } = laidOutFirstPage()
+
+ editor.graph.withLayoutMutations(() => editor.graph.updateNode(card.id, { height: 60 }))
+ editor.graph.updateNode(otherCard.id, { width: 140 })
+
+ expect(layouts.isCurrent(first)).toBe(true)
+ editor.dispose()
+ })
+
+ test('needs layout again once the text measurer changes', () => {
+ const { editor, first, layouts } = laidOutFirstPage()
+
+ setTextMeasurer(() => ({ width: 10, height: 10 }))
+
+ expect(layouts.isCurrent(first)).toBe(false)
+ editor.dispose()
+ })
+
+ test('needs layout again in a replaced document, whose pages can share ids', () => {
+ const { editor, first, layouts } = laidOutFirstPage()
+
+ editor.replaceGraph(new SceneGraph())
+
+ expect(layouts.isCurrent(first)).toBe(false)
+ editor.dispose()
+ })
+
+ test('was never laid out until recorded', () => {
+ const { editor, layouts } = laidOutFirstPage()
+ const third = editor.graph.addPage('Third').id
+
+ expect(layouts.isCurrent(third)).toBe(false)
+ editor.dispose()
+ })
+})
diff --git a/src/app/editor/design-check/pages.ts b/src/app/editor/design-check/pages.ts
index f586d37b9..849f8ed6a 100644
--- a/src/app/editor/design-check/pages.ts
+++ b/src/app/editor/design-check/pages.ts
@@ -86,6 +86,11 @@ export function createPageChecks(options: PageChecksOptions) {
store(pageId, issues)
}
+ /** `pageId`'s last result, if nothing on the page changed since it was checked. */
+ function fresh(pageId: string): readonly DesignIssue[] | null {
+ return stale.has(pageId) ? null : (results.value.get(pageId) ?? null)
+ }
+
/** A page changed: its result is out of date until it is checked again. */
function invalidate(pageId: string | null) {
if (!pageId) return
@@ -143,6 +148,7 @@ export function createPageChecks(options: PageChecksOptions) {
notLoaded,
active,
report,
+ fresh,
invalidate,
invalidateAll,
start,
diff --git a/src/app/editor/design-check/session.ts b/src/app/editor/design-check/session.ts
index 0b2ec8964..43ed93f04 100644
--- a/src/app/editor/design-check/session.ts
+++ b/src/app/editor/design-check/session.ts
@@ -43,6 +43,11 @@ export function createDesignCheck(editor: Editor, state: AppEditorState) {
const snapshot = shallowRef<DesignCheckSnapshot | null>(null)
const panelVisible = ref(false)
const focusedIssueId = ref<string | null>(null)
+ /** The layer of the focused issue, which takes the focus with it when it is deleted. */
+ const focusedNodeId = computed(() => {
+ const id = focusedIssueId.value
+ return id ? (snapshot.value?.issues.find((issue) => issue.id === id)?.nodeId ?? null) : null
+ })
const preferences = computed(() => appPreferences.value.designCheck)
const enabled = computed(() => panelVisible.value || preferences.value.showOnCanvas)
@@ -81,7 +86,10 @@ export function createDesignCheck(editor: Editor, state: AppEditorState) {
return graph.onNodeEvents({
created: (node) => touch(node.id),
updated: (id) => touch(id),
- deleted: (_id, parentId) => touch(parentId),
+ deleted: (id, parentId) => {
+ touch(parentId)
+ if (id === focusedNodeId.value) focusedIssueId.value = null
+ },
reparented: (_id, oldParentId, newParentId) => {
touch(oldParentId)
touch(newParentId)
@@ -143,14 +151,27 @@ export function createDesignCheck(editor: Editor, state: AppEditorState) {
if (pagesNeeded.value) pages.invalidateAll()
})
watch(pagesNeeded, (on) => (on ? pages.start() : pages.stop()), { immediate: true })
- watch(snapshot, (current) => current && pages.report(current.pageId, current.issues))
- // The switch itself settles the new page's layout, which changes the scene again, so the
- // check waits for that instead of running once inside the switch and once after it.
+ // Immediate: the first check runs while `enabled` starts up, before this watcher exists.
+ watch(
+ snapshot,
+ (current) => {
+ if (!current) return
+ pages.report(current.pageId, current.issues)
+ // A focused issue the check no longer finds, such as one fixed, has no row left to show.
+ const focused = focusedIssueId.value
+ if (focused && !current.issues.some(({ id }) => id === focused)) focusedIssueId.value = null
+ },
+ { immediate: true }
+ )
+ // A page nothing changed on shows its last result at once. The check still runs once the
+ // switch settles, rather than inside it, since variables can change what a page reports.
watch(
() => state.currentPageId,
- () => {
+ (pageId) => {
focusedIssueId.value = null
editor.setDesignIssueHighlight(null)
+ const cached = enabled.value ? pages.fresh(pageId) : null
+ if (cached) snapshot.value = { pageId, issues: [...cached] }
publishMarkers()
if (enabled.value) schedule()
}
diff --git a/src/components/design-check/DesignCheckPanel.vue b/src/components/design-check/DesignCheckPanel.vue
index 89dd63243..d17fea59c 100644
--- a/src/components/design-check/DesignCheckPanel.vue
+++ b/src/components/design-check/DesignCheckPanel.vue
@@ -37,6 +37,7 @@ const {
isGroupOpen,
setGroupOpen,
clearFilters,
+ showMoreRows,
hoverRow
} = useDesignCheckPanel({ active: () => active, list, initialScope })
@@ -94,7 +95,6 @@ const scopeModel = computed({
v-for="group in groups"
:key="group.ruleId"
:group="group"
- :focused-issue-id="check.focusedIssueId.value"
:open="isGroupOpen(group)"
@update:open="(open) => setGroupOpen(group.ruleId, open)"
@open-row="(row) => void check.openIssue(row.issue)"
@@ -102,6 +102,7 @@ const scopeModel = computed({
@fix="(row) => row.action && check.applyFixes([row.action.request])"
@fix-all="check.applyFixes(group.fixes)"
@turn-off="turnOffDesignCheckRule(group.ruleId)"
+ @show-more="showMoreRows(group.ruleId)"
/>
</div>
</section>
diff --git a/src/components/design-check/IssueGroup.vue b/src/components/design-check/IssueGroup.vue
index aecbc8f0e..34a541faf 100644
--- a/src/components/design-check/IssueGroup.vue
+++ b/src/components/design-check/IssueGroup.vue
@@ -6,7 +6,7 @@ import {
DropdownMenuRoot,
DropdownMenuTrigger
} from 'reka-ui'
-import { computed, ref, watch } from 'vue'
+import { computed, ref } from 'vue'
import { useDesignCheckMessages } from '@open-pencil/vue'
@@ -22,13 +22,7 @@ import { designCheck } from '@/theme/design-check'
import IssueRow from './IssueRow.vue'
import type { IssueGroupView, IssueRowView } from './types'
-/** Rows rendered before a group asks to show the rest. */
-const ROW_PAGE_SIZE = 50
-
-const { group, focusedIssueId = null } = defineProps<{
- group: IssueGroupView
- focusedIssueId?: string | null
-}>()
+const { group } = defineProps<{ group: IssueGroupView }>()
const open = defineModel<boolean>('open', { default: true })
const emit = defineEmits<{
openRow: [row: IssueRowView]
@@ -36,6 +30,7 @@ const emit = defineEmits<{
fix: [row: IssueRowView]
fixAll: []
turnOff: []
+ showMore: []
}>()
const messages = useDesignCheckMessages()
@@ -43,19 +38,8 @@ const styles = designCheck()
const menuCls = useMenuUI({ content: 'min-w-40' })
const itemCls = menuItem({ justify: 'start' })
const menuOpen = ref(false)
-const limit = ref(ROW_PAGE_SIZE)
-
-// A focused row past the ones shown, such as one a canvas marker opened, shows its page too.
-watch(
- () => (focusedIssueId ? group.rows.findIndex((row) => row.issue.id === focusedIssueId) : -1),
- (index) => {
- if (index >= limit.value) limit.value = Math.ceil((index + 1) / ROW_PAGE_SIZE) * ROW_PAGE_SIZE
- },
- { immediate: true }
-)
-const visibleRows = computed(() => group.rows.slice(0, limit.value))
-const hiddenCount = computed(() => group.rows.length - visibleRows.value.length)
+const hiddenCount = computed(() => group.count - group.rows.length)
</script>
<template>
@@ -108,7 +92,7 @@ const hiddenCount = computed(() => group.rows.length - visibleRows.value.length)
<ul :class="styles.rows()">
<IssueRow
- v-for="row in visibleRows"
+ v-for="row in group.rows"
:key="row.issue.id"
:row="row"
@open="emit('openRow', row)"
@@ -121,7 +105,7 @@ const hiddenCount = computed(() => group.rows.length - visibleRows.value.length)
color="primary"
size="xs"
:class="styles.more()"
- @click="limit += ROW_PAGE_SIZE * 4"
+ @click="emit('showMore')"
>
{{ messages.showMore({ count: hiddenCount }) }}
</AppButton>
diff --git a/src/components/design-check/rows.ts b/src/components/design-check/rows.ts
index 1edc72efb..65e052e1d 100644
--- a/src/components/design-check/rows.ts
+++ b/src/components/design-check/rows.ts
@@ -52,12 +52,12 @@ export function issueRowView(issue: DesignIssue, context: RowContext): IssueRowV
}
/**
- * A rule's group. Rows are built only when it is open, since each reads its layer and a large
- * page has thousands of issues; fixes skip layers deleted since the check either way.
+ * A rule's group with its first `shownRows` rows: each row reads its layer and a large page has
+ * thousands of issues, so only rows on screen are built. Fixes skip deleted layers either way.
*/
export function issueGroupView(
group: DesignIssueGroup,
- open: boolean,
+ shownRows: number,
context: RowContext
): IssueGroupView {
const fixes = group.issues.flatMap(({ nodeId, fix }) =>
@@ -69,7 +69,7 @@ export function issueGroupView(
title: ruleTitle(group.ruleId, context.messages),
help: ruleHelp(group.ruleId, context.messages),
count: group.issues.length,
- rows: open ? group.issues.map((issue) => issueRowView(issue, context)) : [],
+ rows: group.issues.slice(0, shownRows).map((issue) => issueRowView(issue, context)),
fixes,
bindsOnly: fixes.every(({ fix }) => fix.kind === 'bind-variable')
}
diff --git a/src/components/design-check/types.ts b/src/components/design-check/types.ts
index 54085cd51..586a27f65 100644
--- a/src/components/design-check/types.ts
+++ b/src/components/design-check/types.ts
@@ -24,9 +24,9 @@ export interface IssueGroupView {
severity: DesignIssueSeverity
title: string
help: string | null
- /** How many issues the group lists, whether or not its rows are built. */
+ /** How many issues the group lists, whether or not their rows are built. */
count: number
- /** The rows of an open group; a collapsed group builds none. */
+ /** The rows shown: none while the group is collapsed, its first page or more while open. */
rows: IssueRowView[]
/** Safe fixes of the rows, which the group applies together. */
fixes: LintFixRequest[]
diff --git a/src/components/design-check/useDesignCheckPanel.ts b/src/components/design-check/useDesignCheckPanel.ts
index 660b2fbf7..10326aa99 100644
--- a/src/components/design-check/useDesignCheckPanel.ts
+++ b/src/components/design-check/useDesignCheckPanel.ts
@@ -19,6 +19,10 @@ import { issueGroupView, type RowContext } from './rows'
import type { DesignCheckScope, IssueGroupView, IssueRowView } from './types'
import { usePresetLabels } from './usePresetLabels'
+/** Rows an open group shows at first, and how many more each "show more" adds. */
+const ROW_PAGE = 50
+const MORE_ROWS = ROW_PAGE * 4
+
/**
* State of the Lint panel: scope, filters, grouped rows and empty states. While the panel is
* shown it keeps the design check running and brings focused issues into view in `list`.
@@ -37,6 +41,9 @@ export function useDesignCheckPanel(options: {
const visibleSeverities = ref<DesignIssueSeverity[]>([...DESIGN_ISSUE_SEVERITIES])
/** Explicit open state per rule; suggestions start collapsed, problems start open. */
const openGroups = reactive(new Map<string, boolean>())
+ /** Rows shown per rule once more than the first page was asked for, until the list changes. */
+ const rowLimits = reactive(new Map<string, number>())
+ watch([options.active, () => store.state.currentPageId, scope], () => rowLimits.clear())
// Issues in scope
@@ -83,7 +90,7 @@ export function useDesignCheckPanel(options: {
visibleSeverities.value.includes(issue.severity)
)
return groupIssuesByRule(shown).map((group) =>
- issueGroupView(group, isGroupOpen(group), context)
+ issueGroupView(group, isGroupOpen(group) ? rowLimit(group.ruleId) : 0, context)
)
})
@@ -109,6 +116,20 @@ export function useDesignCheckPanel(options: {
openGroups.set(ruleId, open)
}
+ function rowLimit(ruleId: string): number {
+ return rowLimits.get(ruleId) ?? ROW_PAGE
+ }
+
+ function showMoreRows(ruleId: string) {
+ rowLimits.set(ruleId, rowLimit(ruleId) + MORE_ROWS)
+ }
+
+ /** Shows a group's rows at least up to `index`, a whole page at a time. */
+ function showRowsUpTo(ruleId: string, index: number) {
+ if (index >= rowLimit(ruleId))
+ rowLimits.set(ruleId, Math.ceil((index + 1) / ROW_PAGE) * ROW_PAGE)
+ }
+
function clearFilters() {
visibleSeverities.value = [...DESIGN_ISSUE_SEVERITIES]
}
@@ -164,6 +185,11 @@ export function useDesignCheckPanel(options: {
visibleSeverities.value = [...visibleSeverities.value, issue.severity]
}
openGroups.set(issue.ruleId, true)
+ const ruleIssues = scopedIssues.value.filter(({ ruleId }) => ruleId === issue.ruleId)
+ showRowsUpTo(
+ issue.ruleId,
+ ruleIssues.findIndex(({ id }) => id === issueId)
+ )
await nextTick()
options.list.value
?.querySelector(`[data-issue-id="${CSS.escape(issueId)}"]`)
@@ -193,6 +219,7 @@ export function useDesignCheckPanel(options: {
isGroupOpen,
setGroupOpen,
clearFilters,
+ showMoreRows,
hoverRow
}
}
diff --git a/tests/app/editor/design-check/pages.test.ts b/tests/app/editor/design-check/pages.test.ts
index 678741a1d..05ce13673 100644
--- a/tests/app/editor/design-check/pages.test.ts
+++ b/tests/app/editor/design-check/pages.test.ts
@@ -78,6 +78,19 @@ describe('background page checks', () => {
checks.stop()
})
+ test("give a page's last result only while nothing on it has changed", () => {
+ const { first, checks } = setup()
+ checks.start()
+ const issues = [issue('live', first.id, 'warning')]
+ checks.report(first.id, issues)
+
+ expect(checks.fresh(first.id)).toEqual(issues)
+
+ checks.invalidate(first.id)
+ expect(checks.fresh(first.id)).toBeNull()
+ checks.stop()
+ })
+
test('leave pages a large file has not loaded unchecked', async () => {
const { first, second, third, checked, checks } = setup(['Third'])
diff --git a/tests/app/editor/design-check/session.test.ts b/tests/app/editor/design-check/session.test.ts
index 197fc2d78..1c1b151be 100644
--- a/tests/app/editor/design-check/session.test.ts
+++ b/tests/app/editor/design-check/session.test.ts
@@ -34,6 +34,19 @@ function twoPagesWithIssues() {
return { store, first, second, firstText, secondText, checkedPages, markedNodes }
}
+/** The editor's own switch; the app's adds a progress overlay with timers of its own. */
+async function switchPage(store: ReturnType<typeof createEditorStore>, pageId: string) {
+ const prepared = await store.preparePage(pageId)
+ if (prepared) store.commitPageSwitch(prepared)
+ await nextTick()
+}
+
+/** Lets the check scheduled after a change run. */
+async function settleCheck() {
+ jest.advanceTimersByTime(1000)
+ await nextTick()
+}
+
describe('the design check across a page switch', () => {
test('checks the new page once, after the switch', async () => {
jest.useFakeTimers()
@@ -42,17 +55,12 @@ describe('the design check across a page switch', () => {
expect(store.designCheck.snapshot.value?.pageId).toBe(first.id)
expect(markedNodes()).toEqual([firstText.id])
- // The editor's own switch; the app's adds a progress overlay with timers of its own.
- const prepared = await store.preparePage(second.id)
- if (prepared) store.commitPageSwitch(prepared)
- expect(store.state.currentPageId).toBe(second.id)
- await nextTick()
+ await switchPage(store, second.id)
// The previous page's markers would point at layers that are no longer shown.
expect(markedNodes()).toEqual([])
expect(checkedPages).toEqual([])
- jest.advanceTimersByTime(1000)
- await nextTick()
+ await settleCheck()
expect(checkedPages).toEqual([second.id])
expect(markedNodes()).toEqual([secondText.id])
})
@@ -79,3 +87,74 @@ describe('the design check across a page switch', () => {
expect(store.designCheck.focusedIssueId.value).toBe(issue.id)
})
})
+
+describe('a page visited before', () => {
+ test('shows its last result at once when nothing on it changed', async () => {
+ jest.useFakeTimers()
+ const { store, first, second, secondText, markedNodes } = twoPagesWithIssues()
+ await switchPage(store, second.id)
+ await settleCheck()
+ await switchPage(store, first.id)
+ await settleCheck()
+
+ await switchPage(store, second.id)
+
+ // Before the check that follows the switch runs.
+ expect(markedNodes()).toEqual([secondText.id])
+ })
+
+ test('shows the first page checked at once too', async () => {
+ jest.useFakeTimers()
+ const { store, first, second, firstText, markedNodes } = twoPagesWithIssues()
+ await switchPage(store, second.id)
+ // The second page's check replaces the first's result; the background checks wait longer.
+ jest.advanceTimersByTime(300)
+ await nextTick()
+
+ await switchPage(store, first.id)
+
+ expect(markedNodes()).toEqual([firstText.id])
+ })
+
+ test('waits for a new check when it changed while away', async () => {
+ jest.useFakeTimers()
+ const { store, first, second, secondText, markedNodes } = twoPagesWithIssues()
+ await switchPage(store, second.id)
+ await settleCheck()
+ await switchPage(store, first.id)
+ await settleCheck()
+ store.updateNode(secondText.id, { fontSize: 16 })
+
+ await switchPage(store, second.id)
+ expect(markedNodes()).toEqual([])
+
+ await settleCheck()
+ expect(markedNodes()).toEqual([])
+ })
+})
+
+describe('the focused issue', () => {
+ test('is dropped as soon as its layer is deleted', () => {
+ const { store, firstText } = twoPagesWithIssues()
+ store.designCheck.openMarker([firstText.id])
+ expect(store.designCheck.focusedIssueId.value).not.toBeNull()
+
+ // Until the next check, the panel still lists the deleted layer's issue and would reveal it.
+ store.deleteSelected()
+
+ expect(store.designCheck.focusedIssueId.value).toBeNull()
+ })
+
+ test('is dropped once the check no longer finds it', async () => {
+ jest.useFakeTimers()
+ const { store, firstText } = twoPagesWithIssues()
+ store.designCheck.openMarker([firstText.id])
+
+ store.updateNode(firstText.id, { fontSize: 16 })
+ await nextTick()
+ jest.advanceTimersByTime(1000)
+ await nextTick()
+
+ expect(store.designCheck.focusedIssueId.value).toBeNull()
+ })
+})
diff --git a/tests/e2e/design-check/design-check.spec.ts b/tests/e2e/design-check/design-check.spec.ts
index 527f34a24..25cb3076f 100644
--- a/tests/e2e/design-check/design-check.spec.ts
+++ b/tests/e2e/design-check/design-check.spec.ts
@@ -419,27 +419,32 @@ test('Canvas markers and Layers panel marks can be turned off from the View menu
/** Sixty small notes in a grid, far enough apart that each one's marker can be clicked. */
const NOTE = { columns: 6, gapX: 100, gapY: 50, width: 40, height: 10, left: 40, top: 60 }
-test('A marker opens an issue past the rows its group shows at first', async () => {
- const lastNoteId = await editor.page.evaluate((note) => {
+/** Adds the notes at zoom 1 and returns their ids in order; each is too small to read. */
+function addNotes(page: Page): Promise<string[]> {
+ return page.evaluate((note) => {
const store = window.openPencil?.getStore?.()
if (!store) throw new Error('OpenPencil store not initialized')
store.state.zoom = 1
store.state.panX = 0
store.state.panY = 0
- let last = ''
- for (let index = 0; index < 60; index++) {
- last = store.graph.createNode('TEXT', store.state.currentPageId, {
- name: `Note ${index + 1}`,
- text: 'Note',
- fontSize: 8,
- x: note.left + (index % note.columns) * note.gapX,
- y: note.top + Math.floor(index / note.columns) * note.gapY,
- width: note.width,
- height: note.height
- }).id
- }
- return last
+ return Array.from(
+ { length: 60 },
+ (_, index) =>
+ store.graph.createNode('TEXT', store.state.currentPageId, {
+ name: `Note ${index + 1}`,
+ text: 'Note',
+ fontSize: 8,
+ x: note.left + (index % note.columns) * note.gapX,
+ y: note.top + Math.floor(index / note.columns) * note.gapY,
+ width: note.width,
+ height: note.height
+ }).id
+ )
}, NOTE)
+}
+
+test('A marker opens an issue past the rows its group shows at first', async () => {
+ const lastNoteId = (await addNotes(editor.page)).at(-1)
await waitForMarkers(editor.page)
// The sixtieth note's row is past the fifty its group lists at first.
@@ -457,3 +462,14 @@ test('A marker opens an issue past the rows its group shows at first', async ()
)
await expect(lintPanel(editor.page).locator(`[data-node-id="${lastNoteId}"]`)).toBeInViewport()
})
+
+test('A group lists its first rows and shows the rest on request', async () => {
+ await addNotes(editor.page)
+ await editor.page.getByRole('tab', { name: /^Lint/ }).click()
+ const rows = lintPanel(editor.page).locator('[data-rule-id="min-text-size"] [data-issue-id]')
+ await expect(rows).toHaveCount(50)
+
+ await lintPanel(editor.page).getByRole('button', { name: 'Show 10 more' }).click()
+
+ await expect(rows).toHaveCount(60)
+})