Skip to content

test(editor): scope createTestEditor's returned locator to the rendered editor#2644

Merged
christianhg merged 1 commit into
mainfrom
fix/test-editor-scoped-locator
May 12, 2026
Merged

test(editor): scope createTestEditor's returned locator to the rendered editor#2644
christianhg merged 1 commit into
mainfrom
fix/test-editor-scoped-locator

Conversation

@christianhg
Copy link
Copy Markdown
Member

createTestEditor from @portabletext/editor/test/vitest mounts the editor through vitest-browser-react's render(), which returns a locator scoped to the freshly-mounted container. It then discarded that scoped locator and reached for page.getByRole('textbox') instead.

const renderResult = await render(<EditorProvider>...</EditorProvider>)

// ...

const locator = page.getByRole('textbox')  // unscoped: document-wide

Two calls in the same DOM expose the bug. The second call's page.getByRole('textbox') matches both editors in document order, returns the first match, so the second locator addresses the first editor instead of its own. Vitest's iframe-per-test isolation hid this in CI; embedders running multiple editors in the same DOM (a Sanity Studio form with two PT inputs, an integration host with a playground next to a test target, anything driven by Playwright that doesn't iframe each scenario) trip it.

Fix is one line: use the scoped locator that render() already returned.

The accompanying regression test mounts two editors, types into each, and asserts each editor ends up with its own content. The test fails on main because the second editor's locator targets the first, so the second userEvent.type writes into the first editor and the second editor's snapshot stays empty.

createTestEditors (plural) already scopes by data-testid per-editor; nothing changes there.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 11, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
portable-text-editor-documentation Ready Ready Preview, Comment May 12, 2026 7:45am
portable-text-example-basic Ready Ready Preview, Comment May 12, 2026 7:45am
portable-text-playground Ready Ready Preview, Comment May 12, 2026 7:45am
racetrack Error Error May 12, 2026 7:45am

Request Review

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 11, 2026

⚠️ No Changeset found

Latest commit: c063ec0

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 11, 2026

📦 Bundle Stats — @portabletext/editor

Compared against main (703e4a99)

@portabletext/editor

Metric Value vs main (703e4a9)
Internal (raw) 745.0 KB -
Internal (gzip) 143.0 KB -
Bundled (raw) 1.35 MB -
Bundled (gzip) 304.0 KB -
Import time 98ms +1ms, +0.6%

@portabletext/editor/behaviors

Metric Value vs main (703e4a9)
Internal (raw) 467 B -
Internal (gzip) 207 B -
Bundled (raw) 424 B -
Bundled (gzip) 171 B -
Import time 3ms +0ms, +2.2%

@portabletext/editor/plugins

Metric Value vs main (703e4a9)
Internal (raw) 3.3 KB -
Internal (gzip) 948 B -
Bundled (raw) 3.1 KB -
Bundled (gzip) 878 B -
Import time 8ms +0ms, +0.3%

@portabletext/editor/selectors

Metric Value vs main (703e4a9)
Internal (raw) 76.3 KB -
Internal (gzip) 14.3 KB -
Bundled (raw) 72.5 KB -
Bundled (gzip) 13.3 KB -
Import time 8ms -0ms, -1.1%

@portabletext/editor/traversal

Metric Value vs main (703e4a9)
Internal (raw) 9.2 KB -
Internal (gzip) 2.4 KB -
Bundled (raw) 9.3 KB -
Bundled (gzip) 2.4 KB -
Import time 5ms +0ms, +0.9%

@portabletext/editor/utils

Metric Value vs main (703e4a9)
Internal (raw) 30.6 KB -
Internal (gzip) 6.5 KB -
Bundled (raw) 28.5 KB -
Bundled (gzip) 6.1 KB -
Import time 7ms +0ms, +0.5%

🗺️ . · ./behaviors · ./plugins · ./selectors · ./traversal · ./utils · Artifacts

Details
  • Import time regressions over 10% are flagged with ⚠️
  • Sizes shown as raw / gzip 🗜️. Internal bytes = own code only. Total bytes = with all dependencies. Import time = Node.js cold-start median.

@christianhg christianhg force-pushed the fix/test-editor-scoped-locator branch from c5f032d to c063ec0 Compare May 12, 2026 07:44
@christianhg christianhg changed the title fix(editor): scope createTestEditor's returned locator to the rendered editor test(editor): scope createTestEditor's returned locator to the rendered editor May 12, 2026
@christianhg christianhg marked this pull request as ready for review May 12, 2026 07:45
@christianhg christianhg enabled auto-merge (rebase) May 12, 2026 07:45
@christianhg christianhg disabled auto-merge May 12, 2026 07:49
@christianhg christianhg merged commit 289e5d8 into main May 12, 2026
17 of 18 checks passed
@christianhg christianhg deleted the fix/test-editor-scoped-locator branch May 12, 2026 07:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant