You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
TSX: String literal expression (e.g. {" "}) causes SSR/client hole count mismatch and hydration element duplication #965
In .tsx components, an explicit string expression like {" "} (commonly generated by formatters like Prettier to preserve whitespace between text and inline tags) causes a mismatch in the dynamic hole count between the client and server compilers:
Minimal Reproduction
import{Link}from"@octanejs/tanstack-router";// or any inline componentexportfunctionExample(){return(<p>
Try the{" "}<Linkto="/items">items</Link> page
</p>);}
Compiler Output Discrepancy
Client compiler (.tsx):
Treats { " " } as a dynamic text expression (h0: " "), creating a template with two holes:
Server compiler (.tsx):
Constant-folds "Try the " + " " into a single static string in the template/output, emitting only one hole:
return`<p> Try the ${ssrComponent(__s,Link,{ ... })} page </p>`;
Hydration Impact
During hydration, the client cursor expects slot 0 to be the whitespace text node. Finding the server-rendered <a> anchor at that DOM position, it consumes that node for slot 0, then proceeds to mount slot 1 (<Link>), inserting a duplicate anchor element immediately after it into the DOM (e.g. rendering itemsitems). When navigating client-side, the router unmounts and mounts the page without hydration, which is why it reverts to 1 link.
Comparison with .tsrx
In .tsrx, string literal expressions like {" "} are statically analyzed and folded directly into the template string at compile time on both client and server (const _t = _$template("<p> Try the <!> page </p>")), so .tsrx does not allocate a dynamic text hole and is unaffected.
Activity
fix(compiler): fold tsx string-literal children for hydration (#972)