Repository navigation
fix(studio): a file is a composition only when a browser would build an element carrying data-composition-id - #8831
jrusso1020 wants to merge 5 commits into
Conversation
…a-composition-id Studio listed and previewed any HTML file whose text held data-composition-id=, so a page saved by capture could show up as a composition. The check now needs a closed start tag with an attribute of exactly that name and a value, read from the file's own text. Capture rewrites the marker to text that cannot join with what follows it. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ines Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
Live Studio check: not run. I tried to start Studio on 127.0.0.1 from this branch three ways (from source, from a fresh CLI build, and from the built binary) and it would not start in my checkout, for build reasons unrelated to this change. What stands in for it: the route tests in Signed: Rames |
Edit accuracy: accurate 273 (base branch 271), smooth 54 of thoseThe gate passes. Newly passing (2)
Not banked yet, reported and not gated (bank a full-grid run's baseline.json) (2)
Quarantined, measured but not gated (0) |
… check Same result for every input; the attribute walk no longer uses patterns that start with an optional run of whitespace. Signed: Rames Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
jerry-heygen
left a comment
There was a problem hiding this comment.
Changes requested at 05249726. The capture marker rewrite is an improvement, but isCompositionSource still treats tag-shaped text in script or style content as an actual element. This predicate is used to admit files to composition preview, not just to populate the list, so it cannot rely on a text scan that disagrees with the HTML parser about what is an element.
Use a namespace-aware HTML parse for the admission check. Preserve the valid inline SVG case, and add a regression that raw-text content alone does not qualify a file for composition preview. Exact-head lint, CLI and Studio Server test steps ran and passed. This is a source review; I did not run Studio or reproduce the security behavior.
— Jerrai (pr-review)
… build the marked element The check now parses the page as a browser with scripting on does, so a tag written inside a script, style, comment, noscript or other text is no element, and inline SVG is read as a browser reads it. A page nested deeper than a browser nests, with thousands of attributes on one tag, or that makes more elements than it has characters is not a composition. An empty data-composition-id is not a composition either. The answer is kept per page content, so a listing parses each page once. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
jerry-heygen
left a comment
There was a problem hiding this comment.
Changes requested at 90781438. The new parser addresses the raw-text issue and preserves inline SVG. The remaining blocker is that composition discovery now builds a full HTML tree synchronously on the Studio server's request thread (routes/projects.ts:9–18, helpers/hfIdPersist.ts:94–131). The async file reads do not move parsing off that thread. The depth and per-tag limits do not bound total work across files, and the cache does not help on a first scan or after files change. The timings in the PR already show a single large page taking about a second on a cold parse; a project scan can spend that time on multiple files while unrelated Studio requests wait.
Keep the parser, but run discovery parsing off the request thread with bounded concurrency and a limit on total work. Add a route-level check that an unrelated Studio request can still complete during a cold scan. Exact-head CI was still running at the review cut. This is a source review; I did not run Studio or independently benchmark it.
— Jerrai (pr-review)
…ld worker, not the request thread Parsing a page holds a thread for as long as it takes, so the listing hands the pages to the build worker and waits. One scan has 30 seconds from the moment the worker starts it. When pages are left unread by then, or the scan does not end, the answer carries the files but no composition list, with one log line; Studio keeps the list it has, and the next listing goes on from what the worker already learned. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
jerry-heygen
left a comment
There was a problem hiding this comment.
Changes requested at 351927c4. Discovery now parses off the request thread, and the new route test covers that improvement. The remaining issue is the shared preview worker's queue: runOffThread posts every job immediately, but a queued-job timeout only removes the promise from pending. It does not remove the worker message. The worker still runs the expired scan, and compositions starts a fresh time budget when it receives the message. Studio can therefore keep doing listing work after that listing has returned and delay a preview that is still waiting.
Dispatch only jobs that are still live, with a bound on queued discovery work, or isolate discovery from preview building. Add coverage that a listing which expires in the queue does no scan and cannot delay the next preview. Hosted CI was still running at the review cut. This is a source review; I did not run Studio.
— Jerrai (pr-review)
What
data-composition-idattribute has a value. A template's content counts. Before, the textdata-composition-id=anywhere in the file was enough.hyperframes capturerewrites the marker in a saved page tohf-captured-composition-key, text that cannot join with what follows it to spell the marker again.Behaviour changes
/preview/comp/build answers as for any non-composition file. This replaces the earlier version of this PR, which still counted a full tag written inside a script or style.divwritten inside an SVGstyleorscriptis an element to a browser (it ends the SVG), so it counts.<div data-composition-id="">and<div data-composition-id>are refused. When a tag repeats the attribute, the first one decides, as in a browser.extracted/still works.Why
A page saved by capture is not a composition, and capture strips the marker so Studio leaves it alone. The strip ran once, and its replacement ended in the letter the marker starts with, so
data-composition-idata-composition-id=came out still holding the marker. Studio's text check then listed the saved page and built a preview from it.Why the parser changed: the first versions of this PR scanned tags by hand, and then read the page with linkedom. Both disagree with a browser on where script text, comments and end tags stop, and each disagreement needed its own guard. linkedom (htmlparser2 underneath) is not a spec parser: it reads
<script/>,</script/>,<![CDATA[,--!>, a quoted>inside an end tag and an unclosednoscriptdifferently from a browser. parse5 implements the HTML parsing algorithm, so none of those need a guard.Fails without the fix: "answers another request while a first listing still parses a large page" fails on the listing as it was one commit earlier, where the 12 MB page was parsed on the request thread and the listing answered first.
Also fails without the fix: at the head before the parser change of this PR the check accepts the rows of "refuses a tag that is only text to a browser" from the script string through the first plaintext row, and the empty value; "returns null for a page whose only marker is text a browser does not read as a tag" and "does not list a page whose only marker is a tag written inside a script" fail. On
mainthe old text check also accepts 11 of the 12 earlier refusal cases, and the old strip leaves the marker in 3 of the 5 capture cases.Related work
No issue. Touches only
isCompositionSourceand its three callers (listing, comp preview builder, hf-id stamping) and the capture strip.How
parse5with scripting on, and a walk over the document, template content included.packages/studio-servergains"parse5": "8.0.1". That exact version is already inbun.lock(jsdom uses it), so the lockfile changes by that one line and nothing new is downloaded. The pin is exact because the limits below use parse5'sParserclass and aTokenizersubclass, which a minor release may change. The CLI bundle builds with the parser inside it.Test plan
hfIdPersist.test.ts, 80 tests: 21 accepted shapes (plain, upper case, templates, inline SVG, a script that only names the marker before a real root, a root before<plaintext>), 14 earlier refusals, 25 rows of text that only looks like a tag, and the limits (500 deep accepted, 600 refused; 100,000 uncloseddiv,template, table cells,a+divandbeach refused within a second; 4,000 attributes accepted, 100,000 refused; a repeated name; the 24 KB page above; a million siblings and 400,000 moved elements accepted).packages/studio-server: full suite, 2616 pass, 6 skipped. Typecheck, oxlint, oxfmt and the comment check clean.parse5parse with no limits (950 compositions, 0 differences). Two registry components whose only marker is in a usage comment are non-compositions, as they were at the previous head.Not exercised:
Out of scope:
Not fixed here: the preview builder reads the file a second time after the check, so a file replaced between the two reads is judged on one text and built from the other. It was so before this PR.
Self-review: read the full diff after the last change and ran a second review pass on it, which found three inputs that were slow or memory-hungry; all three have a limit and a test above. Rollout: ships with the next CLI and Studio release. Rollback: revert this commit.
Signed: Rames
🤖 Generated with Claude Code