Application startup and runtime
The viewer application turns deployment settings and registered platform capabilities into a working browser viewer. Startup selects runtime configuration, prepares shared services, registers built-in and runtime-loaded extensions and modes, and exposes them through routes that can load studies from a chosen source.
Startup lifecycle
The startup lifecycle moves from a static web page to a configured React application. The build places the selected configuration at app-config.js, and the browser entry point can replace it with an approved runtime configuration before rendering. This keeps deployment choices outside the main application bundle while the build still selects the bundled extensions and modes.
The application package requires Node 24 or newer. Its build and development scripts use the shared Rsbuild configuration to produce the browser application or serve it for local use. Other scripts select deployment configurations and test entrypoints for those same startup paths.
The main stages are:
- The HTML page sets the public URL and loads the generated application configuration.
- platform/…/index.js checks whether a runtime configuration URL is allowed and replaces the page configuration when one is supplied.
appInitcreates the managers and registers the core services.- The application loads configured and bundled extensions, then loads modes and their custom values.
- React providers expose application state and services to the route tree, and startup reports any runtime plugin failures through the notification service.
- The router maps study-list, local-file, mode, authentication, and fallback paths to their route components.
This diagram shows how browser input becomes a running viewer.
flowchart TD
A[HTML shell] --> B[app-config.js]
B --> C[Runtime config check]
C --> D[Manager and service setup]
D --> E[Extension registration]
E --> F[Mode loading]
F --> G[React providers]
G --> H[Application routes]
H --> I[Study list or viewer]
References: platform/…/index.html• L194-237 platform/…/index.js• L1-42 platform/…/appInit.js• L34-145 platform/…/App.tsx• L59-201 platform/…/package.json• L9-45
Runtime configuration
Runtime configuration defines the viewer's operating context. It selects the base URL, available modes and extensions, data sources, authentication settings, display features, and optional customization sources. The application keeps this configuration in app-level state so routes and child components can use the active values without rebuilding the route tree.
Configuration sources
The build chooses a configuration file through APP_CONFIG. Development uses the full-featured config/dev.js by default, while production builds use the more restricted config/default.js; an explicit build or start script can select another file. The generated page exposes that file as app-config.js, and window.config becomes the input to application initialization.
The default production configuration favors a narrow trust boundary. It enables a read-only DICOMweb source but leaves local files, URL-driven data sources, dynamic configuration, and URL-driven customization disabled unless a deployment opts in. Development and demo configurations enable more of these features for local or public demonstration workflows.
References: platform/…/webpack.pwa.js• L102-169 platform/…/default.js• L3-19 platform/…/default.js• L27-120 platform/…/dev.js• L3-19 platform/…/dev.js• L21-29 platform/…/appConfig.tsx• L1-13
Runtime overrides
An application can permit a configUrl query parameter through dangerouslyUseDynamicConfig. When enabled, the loader resolves the value to the URL that the browser would fetch and requires an origin allow-list, an anchored regular expression, or both before it fetches JSON. Invalid schemes, missing gates, invalid patterns, and disallowed URLs fail closed, so the original configuration remains in place unless the URL passes the deployment rules.
URL-driven customizations follow a separate allow-list. The configuration maps approved URL prefixes to files, so a customization value can change selected behavior without allowing arbitrary module loading. An unapproved customization prefix stops startup instead of being silently ignored. The shipped customization catalog also lets a user add a selected viewer theme to the launch URL.
Allowed customization files are data-only JSONC inputs. For example, studyBrowser/derivedDateTime is selected with ?customization=studyBrowser/derivedDateTime; it appends an InstanceDateTime detail sourced from the latest instance to derived-series thumbnails while keeping the default series number and instance count. The customization names a registered source and condition rather than loading executable code from the URL. The worklist/legacyWorkList profile selects the older study-list route for comparison or short-term migration work.
References: platform/…/loadDynamicConfig.js• L1-23 platform/…/loadDynamicConfig.js• L24-123 platform/…/index.js• L23-37 platform/…/default.js• L27-39 platform/…/dev.js• L21-28 platform/…/index.html• L145-159 platform/…/legacyWorkList.jsonc• L1-31
Capability registration
The registration boundary connects application configuration to the platform services that the viewer can use. appInit creates managers for commands, services, service providers, hotkeys, and extensions, then gives extensions access to those shared objects. Core services provide common viewer behavior such as notifications, dialogs, measurements, display sets, toolbars, viewports, hanging protocols, authentication, panels, workflows, and study prefetch.
Extensions add modules to this shared registry. A module can provide a data source, viewer or layout capability, command, panel, toolbar item, context provider, or other platform feature. The extension manager keeps these modules available by type and gives each registered data source a named instance. Startup applies bootstrap customizations before extension registration, then applies global customizations after extension defaults exist. This order lets deployment choices change registered capability defaults without changing the extension package.
Modes describe user-facing viewer workflows. Startup loads each configured mode and each bundled mode once, applies its mode configuration, registers worklist commands early, and stores the resulting mode instances in app configuration. A mode is not the viewer by itself. It supplies the route identity, layout choice, study behavior, and links to the extensions that make that workflow possible.
References: platform/…/appInit.js• L1-25 platform/…/appInit.js• L34-81 platform/…/appInit.js• L90-145 platform/…/appInit.js• L151-212 platform/…/ExtensionManager.ts• L68-120 platform/…/ExtensionManager.ts• L215-350 platform/…/ExtensionManager.ts• L359-381
Build-time module set
The build-time module set defines which in-tree or installed plugins can be bundled and loaded by name. The build generates pluginImports.js from platform/…/pluginConfig.json; enabled entries become bundled defaults, while named entries can also be loaded through the browser module loader. The same build step copies plugin assets into the application output so a registered capability can find its static resources at runtime.
The application combines these bundled defaults with config.extensions and config.modes. This split lets a deployment ship a known base set while adding configuration-selected capabilities at application startup.
References: platform/…/pluginConfig.json• L1-115 platform/…/writePluginImportsFile.js• L121-137 platform/…/writePluginImportsFile.js• L259-314 platform/…/index.js• L12-18 platform/…/appInit.js• L93-107
Runtime plugin loading
Runtime plugin loading extends the build-time module set without rebuilding the viewer. A runtime descriptor names an extension or mode package and its URL. The loader checks the URL origin, optional host-version range, module format, package identity, and cross-origin integrity before it turns the package into a registered capability. Same-origin code is allowed by default; other origins need an explicit runtimePluginOrigins entry, and cross-origin descriptors also need a digest.
The loader supports ESM packages through a default export and UMD packages through a declared browser global. It records load and registration results in a runtime audit, then the application shows failures after the notification provider mounts. A failed runtime extension does not have to stop the whole viewer, but a mode cannot provide its workflow when its required module fails.
Runtime plugins use the host's shared copies of the core viewer packages. The host publishes this stable shared-package contract before it fetches the first runtime plugin, while compiled-in modules are shared as each loader branch runs. The service worker keeps /plugins/ on the network so an independently updated plugin is not served from an old static cache.
The runtime loading path is summarized below.
flowchart TD
A[Runtime descriptor] --> B[Resolve URL]
B --> C{Origin and version allowed?}
C -- No --> D[Audit refusal]
C -- Yes --> E{Cross-origin?}
E -- Yes --> F[Verify integrity and load]
E -- No --> G[Load directly]
F --> H[Check module format and package id]
G --> H
H --> I[Register extension or mode]
I --> J[Surface failures to the viewer]
References: platform/…/runtimeExtensionLoader.ts• L12-42 platform/…/runtimeExtensionLoader.ts• L129-153 platform/…/runtimeExtensionLoader.ts• L169-232 platform/…/runtimeExtensionLoader.ts• L269-413 platform/…/runtimeExtensionLoader.ts• L500-588 platform/…/runtimeShared.ts• L1-30 platform/…/runtimeShared.ts• L32-75 platform/…/service-worker.js• L15-31
Route composition
The route tree is the application boundary where registered modes and data sources become reachable viewer workflows. createRoutes combines mode routes with the optional study list, custom routes, local and debug paths, authentication routes, and a final not-found route. All mode and study-list routes are private by default; the authentication service decides whether protection is active and how to handle an unauthenticated user.
The base route comes from routerBasename. It allows the same viewer bundle to run at the domain root or below a path such as /viewer/. The browser router and authentication redirect URLs use the same base so navigation and login callbacks resolve to the deployed location.
References: platform/…/App.tsx• L109-201 platform/…/index.tsx• L98-144 platform/…/index.tsx• L146-207 platform/…/publicUrl.ts• L1-4 platform/…/PrivateRoute.tsx• L1-11
Study list route
The study-list route is the main data-entry path for deployments that show a worklist. It selects the current data source from the URL or application defaults, initializes that source, queries studies from URL filters, and passes the result to the selected study-list experience.
The default study list keeps table filters, sort order, page state, and the chosen data source aligned with the URL. Session storage supplies a short-lived fallback for table state. This makes a study-list URL useful for reloads and links while avoiding a new server query when only client-side pagination changes. Preserved query values such as configuration and customization selections continue across study-list navigation.
The study list also provides a preview side panel. The panel loads series for the selected study and may load thumbnails with bounded parallel work. A deployment can select the modern list or the deprecated legacy list through the workList.variant customization. The legacy choice is intended for comparison and does not match the client-side paging model of the current list.
References: platform/…/index.tsx• L20-27 platform/…/index.tsx• L126-144 platform/…/DataSourceWrapper.tsx• L33-139 platform/…/WorkList.tsx• L41-189 platform/…/SidePanelPreview.tsx• L16-53 platform/…/useStudyListQuery.tsx• L87-160 platform/…/useStudyListStateSync.ts• L28-91 platform/…/useSeriesFetch.ts• L48-73 platform/…/preserveQueryParameters.test.ts• L7-109 platform/…/legacyWorkList.jsonc• L1-31
Mode and data source paths
Each mode route identifies a viewer workflow. A route can name a data source explicitly or omit that segment to use the active data source. The route shape is therefore conceptually /<mode>/<data source> with study and workflow values supplied by query parameters.
The router creates one route for every mode and known data source, plus a mode-only route. ModeRoute selects the active data source, reads path and query values, and hands them to the mode and data source. This lets the same workflow use different archives without changing the mode definition.
References: platform/…/buildModeRoutes.tsx• L4-23 platform/…/buildModeRoutes.tsx• L24-88 platform/…/Mode.tsx• L79-147 platform/…/ExtensionManager.ts• L373-415
Authentication routes
When OIDC configuration is present, the application adds routes for login, logout, the authorization callback, and silent refresh. OIDC means OpenID Connect. It is a sign-in protocol built on OAuth 2. The authentication provider enables the shared authentication service, stores the signed-in user, supplies access tokens to data requests, and sends unauthenticated users to the identity provider.
The callback route completes the sign-in redirect and returns control to the application. The sign-out callback restores the saved page after the identity provider completes logout. Logout also uses a same-origin redirect and a browser storage signal so other tabs can leave the viewer when one tab signs out.
References: platform/…/App.tsx• L164-199 platform/…/OpenIdConnectRoutes.tsx• L29-50 platform/…/OpenIdConnectRoutes.tsx• L100-152 platform/…/OpenIdConnectRoutes.tsx• L167-243 platform/…/CallbackPage.tsx• L3-15 platform/…/SignoutCallbackComponent.tsx• L4-26
Local file route
The local route provides a browser-only entry path for DICOM files and folders. It creates a local data source, reads the dropped files into studies, and navigates to a normal mode URL with the resulting study identifiers. The files remain in the browser and are not sent to a remote server by this flow.
The route can choose a microscopy workflow when the loaded files contain microscopy studies and the microscopy capability is registered. Other local studies use the configured local mode or return to the study-list entry path.
References: platform/…/index.tsx• L71-93 platform/…/Local.tsx• L48-114
Viewer entry flow
Entering a mode turns a URL into a study view. The mode route first loads mode-specific extension dependencies and initializes the selected data source with the route parameters. It then obtains the study identifiers and asks the mode for layout data before it starts route setup and study retrieval.
Route setup applies mode state and customizations, runs any mode-specific initialization, and starts entry validation alongside common study retrieval. The route does not render a layout until its study identifiers, layout data, and extension dependencies are ready. This gate keeps the first viewer render aligned with the selected mode and data source while allowing invalid-study navigation without delaying metadata retrieval.
This diagram shows the main transition from a mode URL to the viewer layout.
sequenceDiagram
participant U as Browser URL
participant R as Mode route
participant E as Extension manager
participant D as Data source
participant S as Viewer services
participant L as Layout
U->>R: Select mode, source, studies, and options
R->>E: Load mode dependencies and defaults
R->>D: Initialize with path and query
D-->>R: Return study identifiers
R->>L: Request layout for studies
R->>S: Apply mode state and customizations
R->>R: Run mode entry validation
R->>D: Retrieve study metadata
D-->>S: Add instances and display sets
S-->>L: Provide arranged viewer state
L-->>U: Render the viewer
References: platform/…/Mode.tsx• L79-147 platform/…/Mode.tsx• L152-217 platform/…/Mode.tsx• L219-305 platform/…/Mode.tsx• L322-481 platform/…/Mode.tsx• L494-571
Study retrieval and layout state
The default route initializer retrieves metadata for the requested studies and listens for new instances. As metadata arrives, the display set service groups it for the viewer. The hanging protocol service then selects the initial arrangement from the available display sets, while remaining retrieval work can continue in the background.
A mode can provide its own route initializer before the default initializer runs. This gives specialized workflows a place to prepare state while preserving the common path for study retrieval and display-set creation. The mode route registers the layout's side panels before the first layout render, then layers mode and application customizations over those lists. It re-applies the panels only when those customizations change them.
Mode dependency extensions initialize their customization defaults before layout setup. This lets a layout read those defaults during entry while keeping later mode and global customization layers as the final source of selected values.
The viewport grid turns the selected hanging-protocol arrangement into viewport panes. Each pane chooses a registered viewport component for its display-set type and reports readiness to the shared grid service. Empty panes can use an extension or customization, while unsupported display sets fall back to an empty pane with a user notice.
User interaction also changes the active pane and can accept a display set drop. A customization can handle the drop first; otherwise the grid asks the hanging-protocol service which panes need updates and applies that result through the command system.
References: platform/…/defaultRouteInit.ts• L16-55 platform/…/defaultRouteInit.ts• L57-97 platform/…/defaultRouteInit.ts• L118-157 platform/…/Mode.tsx• L152-244 platform/…/Mode.tsx• L322-387 platform/…/ViewportGrid.tsx• L23-97 platform/…/ViewportGrid.tsx• L128-169 platform/…/ViewportGrid.tsx• L171-359
Mode lifecycle
Mode entry and exit keep shared services and extensions in a clean state as the user changes workflows. Before a mode enters, services reset their mode state and extensions restore or add their own state. On exit, the mode and its subscriptions clean up first, then the extension manager completes shared cleanup.
Entry validation uses the mode's custom hook when one exists. Otherwise it checks that each requested study is present in the active data source and navigates to the not-found route when a study is absent or the check fails. Navigation is guarded by the route's mounted state so a late validation result does not move the user away from a newer page.
This lifecycle is the handoff between the stable application shell and the mode-specific viewer. It prevents state from one workflow from leaking into the next workflow while still allowing extensions to save state before services reset.
References: platform/…/Mode.tsx• L39-77 platform/…/Mode.tsx• L262-320 platform/…/Mode.tsx• L483-520 platform/…/ExtensionManager.ts• L145-207
Change checklist
When these files or sections are changed, remember to consider these:
- Changes to
routerBasenamemust stay aligned across the browser router, mode links, and OIDC redirect paths. - Changes to pluginConfig.json must preserve the generated module names and the copied public or distribution assets expected by runtime loaders.
- Changes to data source names must update the configuration name, route data source segment, active-data-source selection, and any URL query that selects the source.
- Changes to study-list URL keys must stay aligned between URL parsing, state serialization, data-source filters, and query-parameter preservation during navigation.
- Changes to URL-loaded customization data must preserve the allow-listed path and the customization keys consumed by registered capabilities.
- Changes to
workList.variantmust account for the route-time selection of the legacy list and the different paging behavior of the two study-list experiences. - Changes to mode registration order or customization phases must preserve the point at which extensions can read mode and global customization values.
- Changes to the mode readiness gate must keep dependency loading, data-source initialization, layout creation, study validation, service setup, and the first layout render in the same dependency contract.
- Changes to route entry validation must preserve the active authentication token and prevent late navigation after the mode route is unmounted.
- Changes to thumbnail retrieval must preserve cancellation and blob URL cleanup when the selected study changes.
- Changes to platform/…/package.json runtime requirements or build and start scripts must remain aligned with the shared build configuration and deployment paths.
- Changes to viewport component registration or display-set matching must preserve empty-pane handling, unsupported-content notices, readiness reporting, and display-set drop behavior.
- Changes to runtime plugin descriptors must keep package IDs, ESM or UMD format markers, origin rules, integrity requirements, and host-version ranges aligned with the plugin build.
- Changes to the host shared-package list must stay aligned with the runtime plugin external list because published UMD plugins depend on those browser globals.
- Changes to plugin deployment paths must preserve the service worker's network-only rule for
/plugins/so independent plugin releases are not served from stale caches. - Changes to runtime failure reporting must preserve the audit handoff from loading and registration to the notification provider after React providers mount.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A configuration has no modes | Startup aborts before the route tree can be built | Define at least one configured or bundled mode before appInit completes |
| A configured data source name does not resolve to a registered source | Study-list or viewer entry cannot initialize the selected source | Keep dataSources[].sourceName aligned with the registered data source module and URL value |
| A requested study is not returned by the data source | The route moves to the study-not-found view instead of rendering an empty viewer | Validate the study identifiers against the active source before layout setup |
| Study-list URL keys drift between the reader and writer | Filters or sort state disappear, or the list queries with different values than the URL shows | Use the shared study-list URL contract for both parsing and serialization |
| The legacy study list is selected for a large result set | Its older paging and sort assumptions can produce incorrect controls with current client-side query behavior | Use the legacy profile only for comparison or short-term migration work |
| An OIDC deployment omits a matching callback or base path | Sign-in may succeed but the viewer cannot restore the requested page | Build redirect URLs from the deployed routerBasename and register those paths with the identity provider |
A configUrl or customization URL is outside its allow-list | Startup keeps the base config or stops when an unapproved customization is requested | Enable only trusted URL patterns through the explicit configuration gates |
| Mode dependency defaults are not initialized before layout setup | The layout can start with missing customization values and produce the wrong first panel or control state | Initialize dependency customization modules before the layout and route hooks read them |
| A selected study changes while thumbnail requests are active | Late results can update the wrong preview or retain blob memory | Abort the request run and revoke the blob URLs owned by the previous preview |
| A display set has no matching viewport component | The pane shows an empty fallback and the user receives an unsupported-content notice | Register a viewport component for each supported display-set handler and keep the empty-pane customization valid |
| A runtime plugin uses an unapproved origin or lacks required cross-origin integrity | The plugin is refused before it can run | Allow only trusted origins and publish a valid digest for cross-origin descriptors |
| A runtime plugin declares the wrong ESM or UMD contract or package ID | The code may load but cannot become the intended extension or mode | Match globalName and default-export rules to the bundle format and keep the exported ID equal to packageName |
| A runtime plugin depends on a host package that is not shared | The plugin fails during module evaluation or sees a separate viewer instance | Keep the stable host shared-package contract aligned with plugin externals |
| A plugin is updated independently while the service worker caches its path | Users can run an old plugin after deployment | Keep /plugins/ above the static-resource route and use NetworkOnly |
Key files
| File | Why to read it |
|---|---|
| platform/…/index.js | Browser entry point that combines runtime configuration with bundled modes and extensions |
| platform/…/appInit.js | Startup boundary that creates managers, registers services, and turns modules into runtime capabilities |
| platform/…/App.tsx | Application shell that exposes services through providers and mounts the router |
| platform/…/appConfig.tsx | Application context that makes active runtime configuration available to routes and viewers |
| platform/…/index.tsx | Route composition for study-list, mode, custom, local, protected, and fallback paths |
| platform/…/DataSourceWrapper.tsx | Data-source selection, initialization, study-list query handoff, and active-source changes |
| platform/…/buildModeRoutes.tsx | Mapping between loaded modes, data source names, and viewer URLs |
| platform/…/Mode.tsx | Runtime handoff from a mode URL to initialized study, customization, validation, and layout state |
| platform/…/defaultRouteInit.ts | Common study retrieval and initial hanging-protocol flow |
| platform/…/ViewportGrid.tsx | Boundary between hanging-protocol results, viewport components, user interaction, and the rendered image grid |
| platform/…/ExtensionManager.ts | Registry boundary for extension modules, data sources, and mode lifecycle hooks |
| platform/…/runtimeExtensionLoader.ts | Runtime plugin trust checks, module loading, audit records, registration results, and failure notices |
| platform/…/runtimeShared.ts | Stable browser-global package contract used by runtime-loaded UMD plugins |
| platform/…/service-worker.js | Cache policy that keeps independently deployed runtime plugins on the network |
| platform/…/WorkList.tsx | Current study-list workflow, URL state, preview panel, and mode launch actions |
| platform/…/useStudyListQuery.tsx | Study-list filter query lifecycle and data-source error handling |
| platform/…/useStudyListStateSync.ts | Study-list state contract between the URL, session storage, and table state |
| platform/…/pluginConfig.json | Build-time selection of bundled plugin capabilities |
| platform/…/writePluginImportsFile.js | Build contract that generates module loading and copies plugin assets |
| platform/…/default.js | Secure baseline for a production deployment |
| platform/…/dev.js | Full-featured local runtime configuration |
| platform/…/index.html | Catalog and launch surface for shipped URL customization profiles |
| platform/…/legacyWorkList.jsonc | Example data-only profile that selects the deprecated study-list route |
| platform/…/OpenIdConnectRoutes.tsx | Authentication route and redirect behavior |
| platform/…/package.json | Supported Node runtime and the build, development-server, deployment-target, and test paths |
Related: Viewer application composition, Project scaffolding and plugin distribution