Skip to content

MicroFrontend

Embeds another Mateu UI route as a nested micro-frontend inside the current page. Allows composing independent UI applications.

🎬 Architectures: modules, RemoteMenu, islands and server resolution — on YouTube
MicroFrontend.builder()
.baseUrl("/other-app")
.route("/dashboard")
.consumedRoute("")
.build()
PropertyTypeDefaultDescription
baseUrlString—Base URL of the remote Mateu UI
routeString—Route within the remote app to load
consumedRouteString— (none: the island loads its route as content)Route prefix consumed by the host page. Optional with both CLIENT and SERVER
styleString—Inline CSS
cssClassesString—CSS class names
resolveResolveCLIENTWho asks the remote for the first paint: the renderer (CLIENT) or the host while it builds the view (SERVER). Experimental
timeoutMsIntegerthe remote’sHow long the host waits for it, with resolve = SERVER. Experimental
chromeEmbeddedChrome— (top-level)Makes it a block of this page instead of a page of its own: NONE, COMPACT or PAGE (see Embedded: no page chrome). Experimental
MicroFrontend.builder()
.baseUrl("/fluent") // the embedded app's base path
.route("/components/card") // the specific page to show
.consumedRoute("") // how much of the URL this host page "consumes"
.build()

MicroFrontend is useful when:

  • different teams own different parts of the UI
  • you want to embed a Mateu UI into a larger shell application
  • you need lazy-loading of independently deployed UI modules

Without chrome, an embedded UI behaves as if it were the whole page: its header draws a breadcrumb from the host’s menu and address, and every load renames the browser tab (and may push history or set the favicon) — the host page’s own title loses. When the remote is just a block of the page (a widget, a section of an intranet page), set chrome:

MicroFrontend.builder()
.baseUrl("/tools")
.route("/tools/list")
.chrome(EmbeddedChrome.COMPACT)
.build()

Any value makes it embedded:

  • the window stays the host page’s: no SetWindowTitle, SetFavicon or PushStateToHistory from the remote is applied, and a navigation inside it does not touch the address bar;
  • every request it sends (its load, its actions, its triggers) carries embeddedChrome, and a Mateu server answering such a request sends none of those commands at all;
  • it draws no breadcrumb of its own.

And it keeps as much of its page header as the value says:

chromePage header of the remote
NONEnone: no title, no actions — only the content
COMPACTonly its actions (the toolbar), without the title
PAGEtitle and actions, without a breadcrumb

It works the same with resolve = SERVER: the host asks the remote as embedded, and the island keeps its chrome for every later interaction (which go from the browser straight to the remote). In YAML, chrome: NONE on a MicroFrontend. Both web renderers (Vaadin and Redwood) implement it, and the .NET and Python servers have the option too (MicroFrontend.Chrome / MicroFrontend(chrome=…)): their answers to an embedded island drop the window commands the same way.

Resolving it in the server (resolve = SERVER)

Section titled “Resolving it in the server (resolve = SERVER)”

By default the renderer asks the remote for the micro frontend after it paints the host page: one more request per micro frontend, a layout jump when it arrives, and the user’s token travelling from the browser. For several small fragments per screen that is a poor trade. With resolve = SERVER the host asks the remote while it builds the view and embeds the answer in its own response:

MicroFrontend.builder()
.baseUrl("https://orders.acme.com/ui")
.route("/widgets/pending")
.resolve(Resolve.SERVER)
.timeoutMs(150)
.build()

The host asks the remote exactly what the renderer would have asked: the same route, type and action, and — with no consumedRoute — a content load of the route (when the remote is an app with a shell, the island gets the page, not the remote’s whole app).

It never makes the screen worse than resolving in the client:

  • the host asks every SERVER micro frontend of the view in parallel, and waits at most the largest of their timeouts (capped by mateu.microfrontends.max-budget-ms, default 2000);
  • each one that answers in time is embedded (resolved on the wire); one that is slow, fails or is down goes out exactly as a CLIENT one — the renderer asks for it as always — and the call still running at its deadline is cancelled;
  • resolving is not absorbing: the embedded answer keeps the micro frontend’s base url, route and type, and every action and trigger inside it goes to the remote, exactly as if the renderer had asked. The host never proxies the interaction.

The remote’s commands, messages, banners and app state are left out of what is embedded: the page and the app are the host’s.

The host only ever asks a url under a registered remote — a UI definition can never make the server call anywhere else. A SERVER micro frontend whose base url is not under one is a configuration error: the response fails and nothing is asked.

mateu.remotes=orders,content
mateu.remotes.orders.base-url=https://orders.acme.com/ui
mateu.remotes.orders.timeout-ms=200
# a path on this same server (a reverse proxy in front of it): called at mateu.self-base-url
mateu.remotes.content.base-url=/_content-hub
mateu.remotes.content.identity=forward-authorization
mateu.self-base-url=https://shell.acme.com

Or contribute them from code with a RemoteCatalogSupplier bean (List<RemoteDescriptor> remotes()), or replace the whole registry with your own RemoteRegistry bean. A url belongs to a remote when it has the same scheme, host and port and its path is the remote’s or below it.

SettingDefault
mateu.microfrontends.default-timeout-ms500when neither the micro frontend nor its remote say
mateu.microfrontends.max-budget-ms2000the most a view ever waits

The host calls the remote on the user’s behalf, as the remote’s identity strategy says: forward-authorization (the default: the request’s own Authorization, only ever to a registered remote), none, or the name of a RemoteIdentityStrategy bean of yours — the place for a token exchange for a token whose audience is the remote (Mateu ships no OAuth client).

Every call carries X-Mateu-Correlation-Id (the request’s own, else the trace id of its traceparent, else a new one — replace it with a CorrelationIdProvider bean), and every fragment leaves one line on the io.mateu.microfrontends logger: remote, url, outcome (EMBEDDED, FROM_CACHE, TIMEOUT, ERROR, EMPTY), what the page got instead, duration and correlation id. MicroFrontendResolutionListener beans hear the same events, for metrics.

A view other hosts embed says whether they may cache it — @CacheableFragment(maxAgeSeconds = 60, varyBy = "shared") or, per request, FragmentCachePolicySupplier:

varyByThe host keeps
nonenothing (the default when the view says nothing)
sharedone copy for everybody
userone copy per caller
keyone copy per opaque key the remote computes (e.g. the hash of the user attributes its content targets)

With key, the host remembers each caller’s key for maxAgeSeconds (no round trip meanwhile) and, for a caller it does not know yet, tells the remote which keys it holds (X-Mateu-Fragment-Keys): when the remote computes one of them it answers notModified without the fragment and the host serves its copy. Two callers share an entry only once the remote has said they have the same key. The store is in memory and bounded; declare a FragmentCacheStore bean for a shared one.

On the browser side nothing resolved is ever cached: the client structure caches keep the screen without the embedded answer.

See also ContentSlot, a micro frontend resolved in the server against a content service.

Both ports resolve micro frontends in the server with the same rules, wire and degradation as Java (conformance-pinned). What differs is the declaration and the configuration: there are no mateu.remotes.* properties — remotes and limits are server options.

.NET — Resolve = Resolve.Server on the fluent MicroFrontend; remotes in MateuOptions.Remotes (or IRemoteCatalogSupplier services):

builder.Services.AddMateu(o =>
{
o.Remotes.Add(new RemoteDescriptor("orders", "https://orders.acme.com", 800));
o.MaxBudgetMs = 1500;
});
[UI("dashboard")]
public class Dashboard : IComponentTreeSupplier
{
public IComponent Component() => new VerticalLayout
{
Content = [new MicroFrontend("https://orders.acme.com", "/orders/summary") { Resolve = Resolve.Server, TimeoutMs = 300 }],
};
}

Replace a collaborator by registering your own service: IRemoteRegistry, IRemoteIdentityStrategy (chosen by name in RemoteDescriptor.Identity), ICorrelationIdProvider, IFragmentCacheStore, IMicroFrontendResolutionListener; on the remote side, [CacheableFragment(maxAgeSeconds)] / IFragmentCachePolicySupplier.

Python — resolve=Resolve.SERVER on components.MicroFrontend; remotes in add_mateu(remotes=[...]) (or RemoteCatalogSupplier subclasses among the sources):

from mateu_ui.uidl import ComponentTreeSupplier, RemoteDescriptor, ui
from mateu_ui.uidl import components as fluent
@ui("dashboard")
class Dashboard(ComponentTreeSupplier):
def component(self):
return fluent.VerticalLayout(content=(
fluent.MicroFrontend(base_url="https://orders.acme.com", route="/orders/summary",
resolve=fluent.Resolve.SERVER, timeout_ms=300),
))
ORDERS = RemoteDescriptor("orders", "https://orders.acme.com", 800)
# add_mateu(app, my_module, remotes=[ORDERS], max_budget_ms=1500)

The other options (default_timeout_ms, self_base_url, remote_registry, identity_strategies, fragment_cache_store, correlation_id_provider, resolution_listeners) are in the server options tables of the Python and .NET manuals.

See it live in the Explorer: MicroFrontend · MicroFrontend — CLIENT vs SERVER resolution · Embedded chrome — NONE / COMPACT / PAGE · Fragment cache (varyBy)