Marko 5 Interop

TL;DR
  • marko@6 is not backward compatible with the Class API
  • marko@5 is 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.

Comment Opt-In

A comment matching use class or use tags in a template, tag, or attribute-tag body explicitly selects the API for that file:

// use class
<h1>Class API</h1>
// use class
h1 -- Class API
// use tags
<h1>Tags API</h1>
// use tags
h1 -- Tags API

Any Marko comment form (//, /* */, or <!-- -->) works in those body positions; comments inside opening tags or inside <script>/static blocks are ignored.

Tip

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.marko or +layout.marko.

Class API Syntax

An otherwise ambiguous file compiles as Class API if it contains:

Note

static, server, and client statements work in both APIs and are not detection signals.

Tags API Syntax

An otherwise ambiguous file compiles as Tags API if it contains:

<let/count=0>
<button onClick() { count++ }>${count}</button>
let/count=0
button onClick() { count++ } -- ${count}

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.marko

If 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.marko

Limitations

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.