diff --git a/packages/runtime-playground/src/editor-command-runners.ts b/packages/runtime-playground/src/editor-command-runners.ts index a1f42601..fbf68f2a 100644 --- a/packages/runtime-playground/src/editor-command-runners.ts +++ b/packages/runtime-playground/src/editor-command-runners.ts @@ -630,7 +630,7 @@ export async function runEditorOpenCommand({ const waitStartedAt = now() const waitStartedAtMs = Date.now() try { - const readiness = await waitForEditorOpenReadiness(page, target.waitSelector, waitTimeoutMs) + const readiness = await waitForEditorOpenReadiness(page, target, target.waitSelector, waitTimeoutMs) editorReadiness = readiness.editorReadiness editorCanvasReadiness = readiness.editorCanvasReadiness finalUrl = page.url() @@ -812,8 +812,8 @@ export function editorOpenArtifactFilesForCapture(capture: ReadonlySet, } } -export async function waitForEditorOpenReadiness(page: import("playwright").Page, waitSelector: string | undefined, timeoutMs: number): Promise<{ editorReadiness: BrowserEditorReadinessSummary; editorCanvasReadiness?: BrowserEditorCanvasProbeSummary }> { - const editorReadiness = await waitForEditorSemanticReadiness(page, timeoutMs) +export async function waitForEditorOpenReadiness(page: import("playwright").Page, target: EditorOpenTarget, waitSelector: string | undefined, timeoutMs: number): Promise<{ editorReadiness: BrowserEditorReadinessSummary; editorCanvasReadiness?: BrowserEditorCanvasProbeSummary }> { + const editorReadiness = await waitForEditorSemanticReadiness(page, target, timeoutMs) if (!waitSelector) { return { editorReadiness } } @@ -1781,8 +1781,8 @@ async function waitForEditorReadiness(page: import("playwright").Page, timeoutMs // Opening and validating an editor require the block-editor data store. Global // block APIs and save availability are stricter, separate capabilities. -async function waitForEditorSemanticReadiness(page: import("playwright").Page, timeoutMs: number): Promise { - return page.waitForFunction(() => { +async function waitForEditorSemanticReadiness(page: import("playwright").Page, target: EditorOpenTarget, timeoutMs: number): Promise { + return page.waitForFunction((expectedPostId) => { const win = window as unknown as { wp?: { blocks?: { parse?: unknown; getBlockTypes?: () => unknown[] } @@ -1804,16 +1804,20 @@ async function waitForEditorSemanticReadiness(page: import("playwright").Page, t const dispatch = win.wp?.data?.dispatch const editor = select("core/editor") const editorDispatch = typeof dispatch === "function" ? dispatch("core/editor") : undefined + const postId = typeof editor?.getCurrentPostId === "function" ? editor.getCurrentPostId() : undefined + if (expectedPostId !== null && Number(postId) !== expectedPostId) { + return false + } return { schema: "wp-codebox/editor-readiness/v1", status: "ready", storesAvailable: Boolean(editor && blockEditor), canSave: typeof editorDispatch?.savePost === "function", ...(Array.isArray(blockTypes) ? { blockTypesRegistered: blockTypes.length } : {}), - postId: typeof editor?.getCurrentPostId === "function" ? editor.getCurrentPostId() : undefined, + postId, postType: typeof editor?.getCurrentPostType === "function" ? editor.getCurrentPostType() : undefined, } - }, undefined, { timeout: timeoutMs }).then(async (handle) => { + }, target.kind === "post" && target.postId ? target.postId : null, { timeout: timeoutMs }).then(async (handle) => { const readiness = await handle.jsonValue() as BrowserEditorReadinessSummary | false if (!readiness) { throw new Error("wp-codebox-editor-readiness-timeout: Gutenberg block runtime did not become available") diff --git a/tests/browser-routed-command-security.test.ts b/tests/browser-routed-command-security.test.ts index 3f5bdb4e..081b13d0 100644 --- a/tests/browser-routed-command-security.test.ts +++ b/tests/browser-routed-command-security.test.ts @@ -24,6 +24,7 @@ const PARENT_CANVAS_PRESENTATION_IDENTITY = "f".repeat(64) const SLOW_PRESENTATION_IDENTITY = "1".repeat(64) const PENDING_STYLES_PRESENTATION_IDENTITY = "2".repeat(64) const GROWING_PRESENTATION_IDENTITIES = ["3".repeat(64), "4".repeat(64)] +const DELAYED_POST_PRESENTATION_IDENTITY = "5".repeat(64) const matchedPresentationMarkup = `
Matched presentation
` const editorShell = `` const slowPresentationEditorHtml = `${editorShell}` const pendingStylesEditorHtml = `${editorShell}` +const delayedPostEditorHtml = `${editorShell}