Under The Hood
frontend solidjs SolidJS 1.x / babel-preset-solid

Solid JSX Compilation: HTML Template Cloning & Surgical Node Setters

Last updated
Prerequisites:
Browser DOM `<template>` tag
SolidJS reactivity primitives
  • solidjs
  • compiler
  • jsx
  • template-cloning
  • dom
  • performance

Read at your depth

The practical view

Solid's JSX compiler converts declarative JSX into native browser DOM operations without any runtime Virtual DOM. Static HTML elements are converted into `<template>` elements that are cloned using `cloneNode(true)` for maximum speed. Dynamic bindings (like `{count()}` or `class={active()}`) are compiled into surgical micro-effects that directly update element properties (`el.textContent = ...`, `el.className = ...`).

The same idea in other frameworks

react equivalent
`React.createElement('div', null, ...)` creating virtual DOM trees on every render.

Legacy vs modern

React Virtual DOM Object Output vs SolidJS Template Clone Output

React compiles JSX to VNode object factories; Solid compiles JSX to native DOM `<template>` clones with direct node pointers.

before → after
React Virtual DOM Output
return React.createElement('div', { className: 'card' }, React.createElement('h1', null, title)); // ❌ Object allocation
SolidJS Compiled Output
const _el$ = _tmpl$.cloneNode(true); _$insert(_el$.firstChild, title); // ✅ Native template cloning

Interview gotchas

Context

Interviewers test your knowledge of browser C++ DOM instantiation internals.

The mechanical answer

`cloneNode(true)` executes directly in the browser's optimized C++ engine layer in a single native operation. Calling `document.createElement()`, `setAttribute()`, and `appendChild()` repeatedly requires hundreds of cross-boundary JavaScript-to-C++ bindings calls, which incurs high overhead. Cloning a template HTML fragment is 2-5x faster.

Trap

Do not say that Solid uses `innerHTML` at runtime. Solid parses the HTML string into a `<template>` *once* at module load time, and only uses `cloneNode(true)` during component instantiation.

Under The Hood — a multi-depth technical interview hub.

Third-party licenses Press ⌘ K to search.