Marko 5 Interop
marko@6is not backward compatible with the Class APImarko@5is forward compatible and runs both Class and Tags APIs together- In Marko 5, per-file heuristics select which runtime compiles each template
Marko 5 uses the Class API, while Marko 6 uses the Tags API. Because Marko 6 has removed the Class API, incremental migrations run on Marko 5 at the project root, which ships an interoperable layer for both runtimes.
Because the two runtimes are distinct, minimize crossing between them by grouping Tags API components so they primarily render other Tags API components.
API Heuristics
In Marko 5, the compiler classifies each .marko file as a whole using the heuristics below. Every feature in a single file must belong to the same API; mixing Class API and Tags API syntax in one file is not allowed, and an opt-in comment cannot override conflicting syntax.
Directory Name
Marko 5 discovers Class API tags in components/ directories, while Marko 6 discovers Tags API tags in tags/ directories. Files inside a tags/ directory compile with the Tags API.
Two exceptions apply: files inside a components/ directory nested under tags/ do not inherit the tags/ rule (so they fall through to the remaining heuristics, allowing vendored Class API components inside a tags/ tree), and directories registered through a marko.json tags-dir are unaffected by this rule.
Class API Syntax
An otherwise ambiguous file compiles as Class API if it contains:
- A
class {}block - A
style {}block - Inline JS in a
$ scriptlet; - An attribute argument (
<button onClick("handleClick")>) - Any of these Class API tags (see
getFeatureTypeFromCoreTagNameinfeature-detection.ts):<await-reorderer>,<class>,<include-html>,<include-text>,<init-components>,<macro>,<module-code>, or<while>
static, server, and client statements work in both APIs and are not detection signals.
Exclusive Tag Library
If an ambiguous file discovers tags exclusively in tags/ directories with no components/ directories in scope, it defaults to the Tags API:
src/
+page.marko // Tags API
tags/
some-tag.markoIf any components/ directory is in scope, ambiguous files default to the Class API unless marked with a // use tags comment or Tags API syntax:
src/
components/
some-component.marko
some-page/
+page.marko // Class API
tags/
another-tag.marko
tags/
some-tag.markoLimitations
Attributes, content, attribute tags, and tag parameters all pass across the Class/Tags boundary. Pending promises do not: keep each <await> and the content it renders within a single API rather than passing unsettled <await> content across the boundary.
Contributors
Helpful? You can thank these awesome people! You can also edit this doc if you see any issues or want to improve it.
Comment Opt-In
A comment matching
use classoruse tagsin a template, tag, or attribute-tag body explicitly selects the API for that file:Any Marko comment form (
//,/* */, or<!-- -->) works in those body positions; comments inside opening tags or inside<script>/staticblocks are ignored.Explicit opt-ins are only needed when a file sits outside
tags/and contains no API-specific syntax, such as an ambiguous Marko Run+page.markoor+layout.marko.