Skip to content

native compiler: fragment as component child fails in dom mode (works with babel and in ssr mode) #275

Description

@brenelz

Following the docs' request to file an issue when the native backend differs from expectations (compiler option docs).

Versions

  • vite-plugin-solid 3.0.0-next.13 (default compiler: 'native')
  • @dom-expressions/compiler 0.50.0-next.23
  • solid-js / @solidjs/web 2.0.0-beta.20

Repro

import { Show } from 'solid-js'

export function ClientOnly(props) {
  return (
    <Show when={props.when} fallback={props.fallback ?? null}>
      <>{props.children}</>
    </Show>
  )
}

With generate: 'dom' this fails at transform time:

Error: GenericFailure, Only text and expression component children are implemented in the AST-native milestone

The same source compiles fine with compiler: 'babel', and also with the native compiler in generate: 'ssr' mode — so dom and ssr builds of the same file currently disagree.

Characterization

Direct @dom-expressions/compiler transform() calls with { generate, hydratable: true, moduleName: '@solidjs/web' }:

pattern dom ssr
<Show><>{expr}</></Show> (fragment child, expression inside)
<Show><>text</></Show> (fragment child, text inside)
<Show><><div/></></Show> (fragment child, element inside)
<Show><div/></Show> (element child)
<Show>{expr}</Show> (expression child)
<><div/></> (root fragment)

(<div><>…</></div> fails in both modes, but that looks intentional — ssr mode reports the classic "Fragments can only be used top level in JSX", so it's excluded from the report.)

Context

Hit while upgrading TanStack Router to beta.20 / next.13 (TanStack/router#7850). A whole-repo scan (~1350 solid .tsx/.jsx files) found the fragment-as-component-child pattern only once, so in our case the fix was simply dropping a redundant <>…</> wrapper — but the pattern is valid under babel and presumably common in the wild, and since next.13 makes native the default, existing code hits this as a hard transform error on upgrade.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions