fix(chat): stable code-block geometry, hydration reveal, deduped file stats
Three first-render polish issues: Code blocks jumped at end-of-stream: streaming defers the per-line line-number markup, so the finished decorate pass inserted the gutter column and shifted every code line right. The gutter's horizontal footprint is now reserved with CSS while the markup is deferred, so the final pass only fills in numbers and colors. File references were verified twice per render and re-verified with the wrong directory: the annotation pass's own DOM writes re-triggered its MutationObserver, and the pass also ran before the effective directory resolved — issuing stat probes under an empty directory and a second time under the real one. The observer now ignores the pass's own mutations and annotation waits for a resolved directory. Content replacing the hydration skeleton popped in: it now plays a one-shot 180ms fade (reduced-motion aware); cached session switches never carry the class and stay instant. Also removed the dead disableStaging prop and its unused pendingRevealWork threading. Verified on a production build over CDP: a streamed code block's text keeps its exact x-position across end-of-stream, and stat probes for a message with file mentions are unique per path with the directory header always present. The hydration fade path could not be exercised in the harness (the live event stream pre-populates parts in a single-project environment) and needs an eyeball check on a cold multi-project open.
This commit is contained in:
@@ -345,6 +345,13 @@ const useFileReferenceInteractions = ({
|
||||
if (!container) {
|
||||
return;
|
||||
}
|
||||
// Wait for the real directory: annotating against an empty/fallback
|
||||
// directory issues stat probes under the wrong cache key (and the wrong
|
||||
// server directory), and the pass reruns anyway once the directory
|
||||
// resolves — every link ended up verified twice.
|
||||
if (enabled && !effectiveDirectory) {
|
||||
return;
|
||||
}
|
||||
let cancelled = false;
|
||||
const fileReferenceLinkLimit = getFileReferenceLinkLimit();
|
||||
// On mobile surfaces, file-reference highlighting is disabled entirely — not
|
||||
@@ -398,6 +405,19 @@ const useFileReferenceInteractions = ({
|
||||
};
|
||||
|
||||
const annotateFileLinks = () => {
|
||||
annotationWriteDepth += 1;
|
||||
try {
|
||||
annotateFileLinksInner();
|
||||
} finally {
|
||||
// Let the mutation events from our own writes flush before the
|
||||
// observer starts listening for real content changes again.
|
||||
queueMicrotask(() => {
|
||||
annotationWriteDepth -= 1;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const annotateFileLinksInner = () => {
|
||||
if (fileReferencesEnabled) {
|
||||
wrapBlockCodePathTokens(container);
|
||||
}
|
||||
@@ -526,7 +546,12 @@ const useFileReferenceInteractions = ({
|
||||
|
||||
scheduleAnnotation(FILE_REFERENCE_ANNOTATION_DELAY_MS);
|
||||
|
||||
// Our own annotation writes (path-token wrapping, attribute updates) fire
|
||||
// childList mutations too; observing them re-ran the whole pass — every
|
||||
// link was scanned and verified twice per render.
|
||||
let annotationWriteDepth = 0;
|
||||
const observer = new MutationObserver(() => {
|
||||
if (annotationWriteDepth > 0) return;
|
||||
scheduleAnnotation(FILE_REFERENCE_ANNOTATION_DELAY_MS);
|
||||
});
|
||||
observer.observe(container, {
|
||||
|
||||
Reference in New Issue
Block a user