feat: make rendered Slices discoverable in the DOM - #270
Open
filip-prismic wants to merge 1 commit into
Open
filip-prismic wants to merge 1 commit into
filip-prismic wants to merge 1 commit into
Conversation
angeloashmore
approved these changes
Sep 21, 2026
| "prismic-slice-end:element-id", | ||
| ]) | ||
|
|
||
| await client.getByRole("button", { name: "Remove first" }).click() |
Member
There was a problem hiding this comment.
💡 #idea: Rather than simulating client-side changes, we could do an E2E test. It would use a real preview update to ensure the IDs update in the actual scenario we are building.
I'll let you be the judge if that would be better though.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
Live preview tooling needs a reliable way to identify each rendered Slice without requiring customer code changes or adding wrapper elements that could affect layout.
Related discussion: https://prismic-team.slack.com/archives/C0AUR4LLN2H/p1787730780921609
What this does
SliceZoneadds client-side start and end comments around every Slice with an ID.Even tho this is not the main requirement the comments support Slices that render not only one element, but also fragments (multiple elements) or no elements (null).
Server-rendered HTML remains unchanged, and GraphQL Slices without IDs remain unmarked.
How it works
A small client component renders React-owned text anchors after hydration, empties them before paint, and inserts HTML comments beside them. The comments are refreshed after React updates, so they follow reordered Slices and are removed with deleted Slices.
Playwright coverage verifies server output, hydration, fragments, empty Slices, reordering, and removal.