Pular para o conteúdo
TE737 · Tipos · error

`@()` precisa de um elemento-raiz para carregar o valor

Todo valor de `@()` viaja como custom property de CSS no elemento-raiz do componente (o literal de elemento em posição de cauda), herdando DOM abaixo. Um componente que delega a view inteira — sem raiz de elemento própria — não dá onde os valores andarem. Faça a cauda ser um literal de elemento (um `<div>` de embrulho serve) ou remova a interpolação.

Why this fires

Every @(expr) value travels as a CSS custom property on the component's root element — the element literal in tail position of the fn body. Custom properties inherit down the DOM, so every descendant of the instance reads its own root's value. A component whose view has no element root of its own — it delegates everything to a child component, returns a stored value, or ends in a fragment — gives the values nowhere to ride.

let accent = "red"

fn Broke() -> View {
    let v = <div class="a"><style>.a { color: @(accent); }</style></div>
    v
}
// error[TE737]: `@()` needs a root element to carry its value; this component's view has none

Fix it

Make the tail expression an element literal:

fn Fixed() -> View {
    <div class="a">
        <style>.a { color: @(accent); }</style>
    </div>
}

Wrapping a delegated view in a <div> (or any element) also works — the wrapper becomes the property carrier. If the style needs no interpolation at all, remove the @() and the requirement disappears with it.

See also

  • TE730@() outside a declaration value.
  • TE732 — non-serializable interpolation type.

Veja também

Buscar no Zolo

9 resultados

en