Skip to content

[IMP] owl-core, owl-compiler: type the scope's app and the template contract - #2081

Merged
ged-odoo merged 3 commits into
odoo:masterfrom
mcm-odoo:master-template-contract-mcm
Nov 27, 2026
Merged

ged-odoo merged 3 commits into
odoo:masterfrom
mcm-odoo:master-template-contract-mcm

Conversation

@mcm-odoo

Copy link
Copy Markdown
Contributor

Depends on #2080: this branch is based on it, so its first commits
belong to that PR. Only the last three commits are part of this one.

This is the second step of the series that clarifies the boundaries between
the packages. These are type changes plus one removal: the generated code and
the runtime behaviour are unchanged.

Type the app carried by scopes (owl-core)

Scopes carry the application they belong to, so that plugins and components can
reach it, e.g. to create new roots. Since the concrete App lives in
owl-runtime, core typed it as any. Core only reads two things from it: its
plugin manager and its dev mode.

  • A new ScopeApp interface (exported by owl-core) describes them. It is used
    by Scope, PluginManager and core's useApp.
  • owl-runtime narrows it back: ComponentNode declares its app as an App,
    and runtime's useApp() still returns an App.

Describe the template contract as types (owl-compiler, owl-runtime)

A compiled template is created with (app, bdom, helpers) and calls the
blockdom functions and helpers it receives. Which functions exist and how they
are called was only an agreement between the code generator and owl-runtime.
Renaming a helper or changing its arguments on one side only broke when a
template using it was rendered.

  • Two new types in owl-compiler describe the contract: TemplateBlockDom (the
    six blockdom functions) and TemplateHelpers (every helper, with its
    signature). TemplateFunction uses them instead of any.
  • The code generator only accepts helper and blockdom names from them.
  • owl-runtime's helpers and bdom objects must satisfy them.

Values the generated code only passes along (contexts, nodes, blocks, the app)
stay any: their shape belongs to the runtime. As a side effect, owl.d.ts
now also exports TemplateBlockDom and TemplateHelpers, since
TemplateFunction references them.

Remove the unused shallowEqual template helper (owl-runtime)

Compiled templates used it for t-memo, which was removed in Owl 3, so the
compiler no longer emits it. The public shallowEqual utility (from owl-core)
is unaffected.

Checks

  • npm run build, npm run build:types, npm test (all packages),
    npm run test:types and npm run check-formatting pass. No snapshot changes.
  • Verified that the contract catches mismatches at type-check time: a runtime
    helper with an extra argument, a missing helper and a misspelled helper name
    in the code generator each fail type-checking.

@mcm-odoo
mcm-odoo force-pushed the master-template-contract-mcm branch from b488a1e to 0d8cf0e Compare November 27, 2026 12:06
Scopes carry the application they belong to, so that plugins and
components can reach it (e.g. to create new roots). The concrete App lives
in owl-runtime, so core typed it as `any`. Core actually only reads two
things from it: its plugin manager and its dev mode.

This describes them in a `ScopeApp` interface, used by Scope,
PluginManager and core's `useApp`. owl-runtime narrows it back:
ComponentNode declares its `app` as an App, and runtime's `useApp` still
returns an App.
A compiled template is created with `(app, bdom, helpers)` and calls the
blockdom functions and helpers it receives. Which functions exist and how
they are called was only an agreement between the code generator and
owl-runtime: renaming a helper or changing its arguments on one side
broke only when a template using it was rendered.

The contract is now described by two types in owl-compiler,
TemplateBlockDom and TemplateHelpers, and used on both sides:
- the code generator only accepts helper and blockdom names from them;
- owl-runtime's helpers and bdom objects must satisfy them.

Values the generated code only passes along (contexts, nodes, blocks,
the app) stay `any`: their shape belongs to the runtime. The generated
code is unchanged.
Compiled templates used it for t-memo, which was removed in Owl 3: the
compiler no longer emits it.
@mcm-odoo
mcm-odoo force-pushed the master-template-contract-mcm branch from 0d8cf0e to 3000cef Compare November 27, 2026 12:11
@mcm-odoo
mcm-odoo marked this pull request as ready for review November 27, 2026 12:29
@ged-odoo
ged-odoo merged commit 7dba22e into odoo:master Nov 27, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants