Skip to content

Commit f5870b3

Browse files
r1tsuuclaude
andcommitted
fix(tanstack-start): strip RegExp in toSerializable to unblock SSR bootstrap
Run #4's Map→object fix for versionViewData.clientSchemaMap landed but the versions diff-view shard stayed 0/40. The actual blocker was a separate non-serializable value in the payload — RegExp literals from rich-text feature markdownTransformers (e.g. UPLOAD_PLACEHOLDER_REGEX, /!\[([^\]:]+):([^\]]+)\]\(\)/). toSerializable previously preserved RegExp unchanged. seroval then serializes the regex into the SSR bootstrap script, but with doubled backslashes in source (emits `/!\\[.../` instead of `/!\[.../`). That is syntactically invalid JS regex ("Unmatched ')'"), so the script that populates `window.$_TSR` throws mid-stream. TanStack hydration then fails with "Invariant: Expected to find bootstrap data on window.$_TSR", the client re-renders the tree empty, and the diff wrapper never reaches the DOM — hence every test in `versions/e2e.spec.ts › Versions diff view` timed out waiting for `.render-field-diffs`. Next.js doesn't hit this because its server→client transport is JSON, which silently drops RegExp. Strip RegExp here to match that behavior. Rich-text transformer regexes are server-only (markdown import/export) and aren't referenced by buildVersionFields or any client renderer, so the loss is harmless. Verified locally against test/versions/config.ts: before, the page stuck at the Invariant error with an empty client tree; after, the bootstrap parses, hydration completes, and .render-field-diffs renders through SSR. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 8229869 commit f5870b3

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

packages/tanstack-start/src/utilities/toSerializable.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,19 @@ function stripUnserializable(
5050
return cache.get(obj)
5151
}
5252

53-
if (obj instanceof Date || obj instanceof RegExp) {
53+
if (obj instanceof Date) {
5454
return obj
5555
}
5656

57+
// RegExp: seroval's SSR bootstrap emits regex literals with broken escape
58+
// sequences (e.g. `/!\\[.../` instead of `/!\[.../`), crashing the client
59+
// script that populates `window.$_TSR` and preventing hydration. Rich-text
60+
// feature transformer regexes aren't needed on the client (they drive
61+
// server-side markdown import/export), so strip them here.
62+
if (obj instanceof RegExp) {
63+
return undefined
64+
}
65+
5766
ancestors.add(obj)
5867

5968
if (obj instanceof Map) {

0 commit comments

Comments
 (0)