Skip to main content
A custom widget is one ES module that stands alone: everything it runs travels in its definition, within the definition’s size limit. Heavy libraries are the exception. The platform serves a catalog of named libraries on every widget’s origin, and a widget names in its libraries, at exact versions, the ones it loads from there instead of bundling them; anything it does not name, it bundles. A library loaded from the catalog adds nothing to the definition, and loading React from the catalog keeps one React across react-dom and react-bootstrap, where two copies would break every component that uses hooks. This page lists the catalog, says how the frame resolves a widget’s imports through it, states the rules a build follows to make one module that loads, and gives BlobHub’s light and dark colors. Everything here is what a widget needs without the kit.

The catalog

The catalog is https://blobhub.io/libs/catalog.json, also served at /libs/catalog.json on every widget origin, and it is the complete, current list of libraries and their versions. Each version’s files sit at an immutable path, /libs/<name>/<version>/, on every widget origin, so a widget loads its libraries from its own origin. A published version is never changed or removed, so a widget that names one keeps loading it; a later version of a library is added beside the earlier ones, never in their place. The browser caches each library file as immutable, once per widget origin: on a warm cache a library costs nothing, and on a cold one a download per widget. These are the libraries and versions the catalog holds:
  • Peers. A peer is a catalog library that a library imports by its bare name, so that one instance is shared: React across react-dom and react-bootstrap, the grid’s module registry across ag-grid-react and ag-grid-community, Ace across react-ace and Ace’s modes, and d3-selection across d3-zoom’s transitions. A widget that declares a library declares its peers too: the frame resolves only what the widget declares. A library whose peer is not declared cannot import it, and the widget does not start. catalog.json does not list peers, and neither the CLI nor the server checks them, so this table is where they are found. Everything else a library needs is bundled inside it.
  • Ace. ace-builds holds Ace’s minified files under src-noconflict/, without its workers, since the frame refuses a worker loaded from a URL. A widget sets Ace’s basePath to /libs/ace-builds/1.35.4/src-noconflict, so that Ace loads a mode, theme or snippet itself, and useWorker: false, so Ace runs without its background syntax checker. Each ace-builds/src-noconflict/<file> entry loads ace-builds first, so a mode imported before Ace still finds it.
  • TradingView. tradingview is TradingView’s charting library. It draws its chart in a frame nested in the widget and loads its files from its directory in the catalog, both of which the frame allows, so it works in a widget unchanged; a widget passes library_path: "/libs/tradingview/29.6.0/" when it creates a chart.

The format

  • catalog is the format’s version, 1. A reader refuses a version it does not know: the frame does not load the widget, and blobhub workflow deploy refuses it with WIDGET_CATALOG_UNAVAILABLE.
  • libraries maps each library’s name to every published version of it, each MAJOR.MINOR.PATCH.
  • imports maps each import-map entry the version answers to onto a file, and css lists its stylesheets. Both hold paths relative to /libs/<name>/<version>/, so @xyflow/react 12.1.1’s entry @xyflow/react resolves to /libs/@xyflow/react/12.1.1/index.js.
  • integrity holds the Subresource Integrity value of every file in the version’s module graph: the files imports and css name, and the files they import. A file a library loads itself, outside the import map, is not checked against integrity: TradingView’s bundles have no value, and a mode, theme or snippet Ace loads from its basePath is fetched as a classic script, which an import map’s integrity does not cover. A mode, theme or snippet is checked only when the widget imports it through its ace-builds/src-noconflict/<file> entry.

The import map

When a widget loads, the frame’s bootstrap page reads /libs/catalog.json from the widget’s own origin and, before it imports the entry, writes an import map for exactly the libraries the widget declares: every import-map entry each declared version answers to, mapped to its file under /libs/<name>/<version>/, with the integrity value of every file the version lists. It links each declared library’s stylesheets, with their integrity values, and then the widget’s own, so the widget’s rules come after the catalog’s and can restyle them. Then it imports the entry. A bare import of a declared library’s entry resolves through the map, static or dynamic, in the widget’s code and in the catalog’s libraries alike, which is how a library reaches its peers. A static import loads with the entry; a dynamic one, such as import("mermaid"), loads only when the code reaches it, so a heavy library a widget seldom needs costs nothing until then. An entry ending / answers to every specifier that starts with it, as an import map resolves it. Nothing else resolves. A declared library or version the catalog lacks stops the load, and the playground shows This widget needs <library> <version>, which the catalog does not have. in place of the widget. A bare name no declared library answers to fails the import, and the widget does not start. blobhub workflow deploy catches both before it uploads anything: it refuses a library or version the catalog lacks with WIDGET_LIBRARY_UNKNOWN, and an entry that imports a relative path, a URL, or a bare name no declared library answers to with WIDGET_IMPORT_INVALID. A computed import(expr), which it cannot judge, draws the advisory WIDGET_IMPORT_UNVERIFIED.

Building one module

A widget’s own build writes the directory blobhub workflow build packs, as Deploying shows. Whatever bundler makes it, the output follows these rules; a build that breaks one makes a widget that does not load, or loads broken:
  1. One ES module. The entry is an ES module that exports mount, with the widget’s own dynamic imports inlined: no code splitting and no chunks. The frame loads every file from a blob: URL, which cannot resolve a relative import, so a chunk is never found, and build, deploy and diff refuse a relative import.
  2. Declared libraries stay bare. Every import of a declared library’s import-map entry is left as a bare import, for the import map to resolve, and a declared library is imported only through its entries. Bundled, a library is a second copy beside the one the catalog’s libraries import: with two Reacts, a component that uses hooks fails. Nor does a widget import a path into a declared library that is not one of its entries, such as react-dom/server: left bare it resolves to nothing, and the CLI refuses it.
  3. A CommonJS require() of a declared library becomes an import. A CommonJS dependency that calls require("react") must receive the library the import map loads, through an import. Left as a require, it throws when the module loads, since a browser has no require, and the widget does not start. The CLI cannot see this: a require is not an import.
  4. A declared library’s stylesheet is left out. The bootstrap links the catalog’s stylesheet of every declared library that has one, so the build drops any import of it, from a script or from a stylesheet’s @import. Left bare, the import resolves to nothing, and the CLI refuses it in a script; bundled, it is a second copy in the definition. A stylesheet the catalog does not serve, such as a highlight.js theme, is bundled.
  5. Images and fonts inlined. Every image and font the code or a stylesheet uses is inlined as a data: URL. A stylesheet loaded from a blob: URL cannot resolve a relative url(), and the widget’s origin serves no file of the widget’s, so an image or font left as a file never shows.
  6. index.js and index.css. The output is the entry module, index.js, and, when the widget has styles, one stylesheet, index.css. widget.yaml’s entry names the module, and the bootstrap links every stylesheet in the build after the catalog’s.
With esbuild, a build.mjs in the widget’s project, run with node build.mjs before blobhub workflow build, for the Order Board’s two libraries:
  • external holds every entry of the declared versions, read from the catalog. esbuild also leaves every path under a listed package bare, its stylesheets included, so the widget imports no stylesheet of a declared library. One the catalog does not serve is imported by its path relative to the importing file, such as ../node_modules/highlight.js/styles/github.css, which esbuild bundles.
  • jsx: "automatic" compiles JSX into imports of react/jsx-runtime, an entry the catalog’s React answers to.
  • define replaces process.env.NODE_ENV, which many packages read and a browser does not have.
  • The CommonJS case. esbuild uses a package’s ES module build when the package ships one. When a dependency ships only CommonJS and calls require() on a declared library, esbuild keeps the call, and the module throws Dynamic require of "react" is not supported when it loads. Such a dependency needs a plugin that resolves that require to a module importing the entry and handing its exports back, or a replacement that ships ES modules.

Light and dark

The bootstrap sets <html data-theme> to the page’s theme, light or dark, before the entry loads. hello answers the same theme, and when the page switches between light and dark the host pushes theme.changed (Watches and events), on which the widget sets the attribute itself: the bootstrap sets it only once. A stylesheet keys its dark colors on :root[data-theme="dark"], and a library that draws from script, such as a chart or an editor, is given the theme as an option: from hello on load, and again on each theme.changed. None of the catalog’s stylesheets follows data-theme. Bootstrap’s is light-only, and AG Grid’s and React Flow’s stay light unless switched by a class or option of their own. A widget that uses them restyles them for dark in its own stylesheet, which the bootstrap links after theirs. Here a widget declares a few of the tokens for both themes and draws with them:
color-scheme: dark darkens the frame’s own backdrop, scrollbars and form controls. In mount, the widget follows the page’s theme after load:

Tokens

BlobHub’s own widgets draw with --bh-* custom properties. The frame declares none of them: a widget that takes BlobHub’s look declares the ones it uses, with these values. The core tokens:
  • Status colors. Each of success, danger, warning and info has a mark color, a pale -tint plate, and a -text color for text on that plate.
  • --bh-focus-ring is a color only: a focus ring is box-shadow: 0 0 0 0.2rem var(--bh-focus-ring).
  • The shadows hold a whole box-shadow value. In dark, where a shadow barely shows, each also draws an edge from --bh-border or --bh-border-strong, so a widget that uses a shadow declares that token too.

Storage

A widget keeps a viewer’s preferences, such as a chosen tab or a column’s width, in localStorage on its own origin. No other widget and no page on blobhub.io can read it, and the bridge has no storage call. The origin belongs to the widget’s alias in its blob, so every placement of the widget on the blob’s playgrounds, every build deployed under that alias in any revision, and every person who opens it in the same browser share that storage. A widget therefore keys each entry by the viewer’s id, from hello and viewer.changed, and reads what an earlier build wrote without assuming its shape. What it stores stays in that browser.

See also

  • Custom Widgets: widget.yaml and its libraries, the definition, permissions, and deploying.
  • Bridge Protocol: the entry, the handshake, every call, event and refusal.
  • Security Model: the frame and its origin, the headers that cut it off from the network, and the risks that remain.