# Behavior traces — sveltejs/svelte

> Canonical page: https://codevetter.com/unpack/svelte/behavior-traces

# Behavior traces — sveltejs/svelte

Scanned commit 636eaaaa6f064b55072e7d192bb76dc9d8c4516e (2026-09-18). Generated by codevetter codevetter 1.12.0 on 2026-09-22.

Three flows dominate. (1) Compile: `compile()` resets global state, validates options, parses, strips TS, analyzes, transforms, and re-attaches a public AST. (2) Client startup: `mount()` initialises DOM operation caches, opens a root effect and an error boundary, pushes a component context, invokes the compiled component function, and returns its exports. (3) Update: a `$state` write sets a source, which schedules its reactions into a `Batch`, which is flushed on the microtask or synchronously via `flushSync`. A fourth, the SSR→hydrate round trip, is what the test harness itself exercises on every fixture.
- Compile trace: `remove_bom` → `state.reset` → `validate_component_options` → `_parse(source)` → destructure `parsed.options` into `combined_options` → conditional `remove_typescript_nodes` → `analyze_component(parsed, source, combined_options)` → `transform_component(analysis, source, combined_options)` → `to_public_ast`. — [packages/svelte/src/compiler/index.js#L23-60](https://github.com/sveltejs/svelte/blob/636eaaaa6f064b55072e7d192bb76dc9d8c4516e/packages/svelte/src/compiler/index.js#L23-L60)
- Transform trace (client): `client_component` seeds state with `hoisted: [b.import_all('$', 'svelte/internal/client')]` and an empty `templates` Map, walks the template AST with the visitor table, appends `template.body` into `component_block.body`, pushes a `$$css` const when styles are injected, then re-orders `module.body` so imports stay on top followed by hoisted statements. — [packages/svelte/src/compiler/phases/3-transform/client/transform-client.js#L135-200](https://github.com/sveltejs/svelte/blob/636eaaaa6f064b55072e7d192bb76dc9d8c4516e/packages/svelte/src/compiler/phases/3-transform/client/transform-client.js#L135-L200) [packages/svelte/src/compiler/phases/3-transform/client/transform-client.js#L377-500](https://github.com/sveltejs/svelte/blob/636eaaaa6f064b55072e7d192bb76dc9d8c4516e/packages/svelte/src/compiler/phases/3-transform/client/transform-client.js#L377-L500)
- Mount trace: `mount()` → `_mount()` → `init_operations()` → `component_root(...)` → create an anchor text node via `target.appendChild(create_text())` → `boundary(anchor, { pending }, cb)` → `push({})` to open a component context → assign `props.$$events` if `events` given → set `should_intro = intro` → call `Component(anchor_node, props)`. — [packages/svelte/src/internal/client/render.js#L156-200](https://github.com/sveltejs/svelte/blob/636eaaaa6f064b55072e7d192bb76dc9d8c4516e/packages/svelte/src/internal/client/render.js#L156-L200)
- Hydrate trace: `hydrate()` forces `intro ?? false`, scans forward from `get_first_child(target)` for a comment node whose `data === HYDRATION_START`, throws `HYDRATION_ERROR` if absent, calls `set_hydrating(true)` + `set_hydrate_node(anchor)`, then delegates to the same `_mount` with the discovered anchor. — [packages/svelte/src/internal/client/render.js#L95-145](https://github.com/sveltejs/svelte/blob/636eaaaa6f064b55072e7d192bb76dc9d8c4516e/packages/svelte/src/internal/client/render.js#L95-L145)
- Hydration failure recovery: non-Svelte errors are `console.warn`ed, `options.recover === false` escalates to `e.hydration_failed()`, otherwise `init_operations()` + `clear_text_content(target)` runs and the component falls back to a fresh `mount(component, options)` — with `hydrating`/`hydrate_node` restored in `finally`. — [packages/svelte/src/internal/client/render.js#L118-150](https://github.com/sveltejs/svelte/blob/636eaaaa6f064b55072e7d192bb76dc9d8c4516e/packages/svelte/src/internal/client/render.js#L118-L150)
- Read trace: `get(signal)` adds the signal to `captured_signals`, registers the dependency on `active_reaction`, and takes one of two registration paths depending on whether `REACTION_IS_UPDATING` is set — the post-`await` path deduplicates with `includes.call` because `remove_reactions` would otherwise disconnect still-live deps. — [packages/svelte/src/internal/client/runtime.js#L548-605](https://github.com/sveltejs/svelte/blob/636eaaaa6f064b55072e7d192bb76dc9d8c4516e/packages/svelte/src/internal/client/runtime.js#L548-L605)
- Synchronous flush trace: `flushSync(fn)` sets `is_flushing_sync`, flushes any non-fork `current_batch` before running `fn`, then loops `flush_tasks()` + `current_batch.flush()` until `current_batch === null`, restoring the previous flag in `finally`. — [packages/svelte/src/internal/client/reactivity/batch.js#L1033-1058](https://github.com/sveltejs/svelte/blob/636eaaaa6f064b55072e7d192bb76dc9d8c4516e/packages/svelte/src/internal/client/reactivity/batch.js#L1033-L1058)
- Batch flush trace: `Batch.flush()` clears DEV `source_stacks`, sets `is_processing = true` and `current_batch = this`, runs the private `#process()`, then in `finally` resets `flush_count`, `last_scheduled_effect`, `collected_effects`, `legacy_updates`, `current_batch`, `batch_values`, and `old_values`. — [packages/svelte/src/internal/client/reactivity/batch.js#L668-698](https://github.com/sveltejs/svelte/blob/636eaaaa6f064b55072e7d192bb76dc9d8c4516e/packages/svelte/src/internal/client/reactivity/batch.js#L668-L698)
- `{@html}` trace: the `html()` block runs inside a `template_effect`, short-circuits on unchanged value, uses `parent_node.innerHTML = value` when it is the only child, otherwise builds a `<template>`/`<svg>`/`<math>` wrapper, sets `wrapper.innerHTML`, and inserts the resulting nodes via `anchor.before(...)`. — [packages/svelte/src/internal/client/dom/blocks/html.js#L50-160](https://github.com/sveltejs/svelte/blob/636eaaaa6f064b55072e7d192bb76dc9d8c4516e/packages/svelte/src/internal/client/dom/blocks/html.js#L50-L160)
- HMR trace: `hmr(fn)` wraps the component in a `source(fn)` signal; a `block()` effect reads it, and on change deletes every key from the old `instance`, calls `destroy_effect(effect)`, and re-creates a `branch()` with `set_should_intro(false)` so the swap plays no transitions. — [packages/svelte/src/internal/client/dev/hmr.js#L14-60](https://github.com/sveltejs/svelte/blob/636eaaaa6f064b55072e7d192bb76dc9d8c4516e/packages/svelte/src/internal/client/dev/hmr.js#L14-L60)
- Test trace: `runtime_suite` → `common_setup` builds a `CompileOptions` (forcing `accessors: true` by default and `experimental.async` from `runes && async_mode`) and calls `compile_directory(cwd, 'client')` and `compile_directory(cwd, 'server')` → `run_test_variant` imports from `_output/` and calls `render`, `mount`, or `hydrate` per variant. — [packages/svelte/tests/runtime-legacy/shared.ts#L241-300](https://github.com/sveltejs/svelte/blob/636eaaaa6f064b55072e7d192bb76dc9d8c4516e/packages/svelte/tests/runtime-legacy/shared.ts#L241-L300) [packages/svelte/tests/runtime-legacy/shared.ts#L417-520](https://github.com/sveltejs/svelte/blob/636eaaaa6f064b55072e7d192bb76dc9d8c4516e/packages/svelte/tests/runtime-legacy/shared.ts#L417-L520)
- `compile_directory` trace: wipe `_output/<generate>`, glob every non-`_`-prefixed file, route `.svelte.js` through `compileModule`, plain `.js` through a re-export shim so `_config.js` can share module state, and `.svelte` through optional `preprocess` then `compile`, honouring `.client.svelte`/`.server.svelte` suffixes. — [packages/svelte/tests/helpers.js#L63-140](https://github.com/sveltejs/svelte/blob/636eaaaa6f064b55072e7d192bb76dc9d8c4516e/packages/svelte/tests/helpers.js#L63-L140)
- Message codegen trace: `scripts/process-messages/index.js` deletes and recreates `documentation/docs/98-reference/.generated`, walks `messages/<category>/*.md`, matches `## CODE` headings, and throws on any duplicate code across categories. — [packages/svelte/scripts/process-messages/index.js#L14-50](https://github.com/sveltejs/svelte/blob/636eaaaa6f064b55072e7d192bb76dc9d8c4516e/packages/svelte/scripts/process-messages/index.js#L14-L50)
- Benchmark trace: `benchmarking/run.js` in parent mode filters suites by `process.argv` substrings and forks one child per benchmark; in child mode (`BENCH_SINGLE` set) it calls `$.push({}, true)`, runs the benchmark under `with_cpu_profile`, `$.pop()`s, and `process.send`s the result with an exit callback. — [benchmarking/run.js#L1-50](https://github.com/sveltejs/svelte/blob/636eaaaa6f064b55072e7d192bb76dc9d8c4516e/benchmarking/run.js#L1-L50)

Every claim links to its cited files at the pinned commit. Citations identify source evidence; they do not establish runtime correctness. Independent CodeVetter scan — not reviewed by upstream maintainers.

## Public product links

- [CodeVetter](https://codevetter.com/)
- [Download](https://codevetter.com/download)
- [Documentation](https://codevetter.com/docs/)
- [Source](https://github.com/Codevetter/codevetter)
