-
Notifications
You must be signed in to change notification settings - Fork 998
fix(eclipse): keep accordion content in the server-rendered HTML #8314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gregory-boch-prisma
wants to merge
4
commits into
main
Choose a base branch
from
greg/accordion-content-server-rendered
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+142
−8
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
3caf5d9
fix(eclipse): keep accordion content in the server-rendered HTML
gregory-boch-prisma 173dc07
fix(eclipse): keep closed accordion panels out of the tab order
gregory-boch-prisma 44ffe83
fix(eclipse): honour a controlled value when marking panels inert
gregory-boch-prisma 9b64dae
fix(eclipse): size accordion animations from the mounted content
Reviewer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import assert from "node:assert/strict"; | ||
| import test from "node:test"; | ||
| import { renderToStaticMarkup } from "react-dom/server"; | ||
| import { Accordion, Accordions } from "../src/components/accordion"; | ||
| import { textContent } from "./html-text"; | ||
|
|
||
| // FAQ blocks are the most quotable part of a post, and most AI crawlers do not | ||
| // run JavaScript. The answers have to be in the server-rendered HTML, not only | ||
| // in the RSC payload, which means a closed panel stays mounted. | ||
| const QA: Array<[question: string, answer: string]> = [ | ||
| ["What is Prisma?", "Prisma is an ORM for TypeScript."], | ||
| ["Is it type safe?", "Yes, end to end."], | ||
| ]; | ||
|
|
||
| function render(props: { defaultValue?: string } = {}) { | ||
| return renderToStaticMarkup( | ||
| <Accordions type="single" {...props}> | ||
| {QA.map(([question, answer]) => ( | ||
| <Accordion key={question} title={question}> | ||
| {answer} | ||
| </Accordion> | ||
| ))} | ||
| </Accordions>, | ||
| ); | ||
| } | ||
|
|
||
| function panelTags(html: string): string[] { | ||
| return [...html.matchAll(/<div[^>]*role="region"[^>]*>/g)].map((m) => m[0]); | ||
| } | ||
|
|
||
| test("closed panels ship their answers in the server-rendered markup", () => { | ||
| const html = render(); | ||
| const text = textContent(html); | ||
| for (const [question, answer] of QA) { | ||
| assert.ok(text.includes(question), `question missing from markup: ${question}`); | ||
| assert.ok(text.includes(answer), `answer missing from markup: ${answer}`); | ||
| } | ||
|
|
||
| const panels = panelTags(html); | ||
| assert.equal(panels.length, QA.length); | ||
| for (const panel of panels) { | ||
| assert.match(panel, /data-state="closed"/); | ||
| assert.doesNotMatch(panel, /\shidden=""/, "a closed panel must not be display:none"); | ||
| } | ||
| }); | ||
|
|
||
| test("a closed panel is inert and an open one is not", () => { | ||
| const [open, closed] = panelTags(render({ defaultValue: QA[0][0] })); | ||
| assert.match(open, /data-state="open"/); | ||
| assert.doesNotMatch(open, /\sinert=""/); | ||
| assert.match(closed, /data-state="closed"/); | ||
| assert.match(closed, /\sinert=""/, "links inside a closed panel must stay out of the tab order"); | ||
| }); | ||
|
|
||
| test("a closed panel starts collapsed before hydration", () => { | ||
| // The accordion-up keyframe animates from --radix-accordion-content-height to | ||
| // 0 and falls back to `auto` when the variable is unset, which would play a | ||
| // full-height-to-zero collapse on every closed panel as the page loads. | ||
| for (const panel of panelTags(render())) { | ||
| assert.match(panel, /--radix-accordion-content-height:0px/); | ||
| } | ||
| }); |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.