Skip to content

TSX: String literal expression (e.g. {" "}) causes SSR/client hole count mismatch and hydration element duplication #965

Closed

Description

@NathanBeddoeWebDev

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 component

export function Example() {
  return (
    <p>
      Try the{" "}
      <Link to="/items">items</Link> page
    </p>
  );
}

Compiler Output Discrepancy

  1. Client compiler (.tsx):
    Treats { " " } as a dynamic text expression (h0: " "), creating a template with two holes:

    const _t$0 = _$template("<p> Try the<!><!> page </p>");
    // ...
    return _$createElement(_frag$0, {
      h0: " ",
      h1: _$createElement(Link, { to: "/items" }, "items")
    });
  2. 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

  1. added a commit that references this issue on Sep 6, 2026
    eb32683
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions