The embedded Ontology enables applications to sync Ontology data locally, allowing users to interact with data without network connectivity and install applications as progressive web apps ↗ (PWAs). This guide offers a walkthrough for creating a Foundry application with offline support using the @palantir/lohi-ts library in the "Embedded Ontology React" template.
Before starting, complete standard application setup with the steps below.
To support offline functionality, your application will use WebAssembly (Wasm). You must configure the content security policy to allow Wasm execution.
'wasm-unsafe-eval', including the single quotes.
Without this CSP configuration, your deployed application will fail to initialize. This must be configured before deploying.
Use the repository bootstrapper to create your repository with the Ontology React template.

The template will be configured with the following backing repositories:
osdk-templates-bundle: Provides the embedded Ontology (lohi-ts) application template.lohi-asset-bundle: Contains the lohi-ts library and dependencies.nodejs-bundle: Node.js runtime for CI/CD.The bootstrapper populates .env.development and .env.production with the following variables. Only VITE_FOUNDRY_REDIRECT_URL in .env.production requires manual editing after the repository is created.
| Variable | Purpose |
|---|---|
VITE_FOUNDRY_API_URL | URL of your Foundry enrollment. |
VITE_FOUNDRY_CLIENT_ID | OAuth client ID for your application. |
VITE_FOUNDRY_REDIRECT_URL | OAuth callback URL. |
VITE_FOUNDRY_ONTOLOGY_RID | Resource identifier of the Ontology to sync. |
VITE_FOUNDRY_ONTOLOGY_API_NAME | Ontology API name required by lohi-ts for offline sync. |
At build time, Vite injects these values into index.html as <meta> tags, and src/infra/config.ts reads them back at runtime. You configure values through the .env files; you do not need to edit src/infra/config.ts.
.env.production in your repository.VITE_FOUNDRY_REDIRECT_URL with your website subdomain, substituting your-enrollment with your enrollment name.Copied!1VITE_FOUNDRY_REDIRECT_URL=https://your-subdomain.your-enrollment.palantirfoundry.com/auth/callback
Ensure that your Developer Console OAuth configuration includes this redirect URL.
The template ships with an src/syncConfig.ts file that exports an empty syncedObjectTypes array. This is the only file you need to edit to choose what is available offline.
src/syncConfig.ts.syncedObjectTypes array:Copied!1 2 3 4import { Employee, Task } from "@your-app/sdk"; import { type SyncConfigParam } from "@palantir/lohi-ts"; export const syncedObjectTypes: SyncConfigParam[] = [Employee, Task];
Entries use lohi-ts's SyncConfigParam type. Alongside plain object types, you can pass an object type API name string or an ObjectSetQuery to sync a filtered subset of a type. You can also set per-type options such as peer-to-peer sync. Refer to the @palantir/lohi-ts documentation for details.
Only include the objects that users need offline access to. Syncing too many objects can impact initial load time and storage usage.
This list feeds createAppLohiClient in src/main.tsx, which tells Lohi which object types to sync. The <SyncProvider> in src/router.tsx does not need the list, because it invalidates the entire OSDK cache after each sync.
The template performs background syncs automatically. The SyncProvider runs an initial sync on mount and invalidates the OSDK cache after each successful sync. In the template, its syncInterval property is set to 10_000 milliseconds (10 seconds) to enable periodic background syncing. Remove the property to sync only on mount and on demand, such as when a user selects the sync status pill. The <SyncGate> component in src/Home.tsx holds the interface until the first sync completes.
To run a sync directly, use the useLohiClient hook from src/infra/lohi/LohiContext.tsx. For an action that must reach live Foundry rather than being applied optimistically, wrap the subtree in <StandardClientScope> and use the useOnlineAction hook from src/infra/lohi/useOnlineAction.ts. This hook re-syncs and invalidates the cache after the action succeeds.
For more details on using an embedded Ontology in your application, refer to the README.md in your generated repository.
With the template configured, you can now develop your application logic offline, or in a VS Code workspace.
The template is pre-configured with the following features:
@palantir/lohi-ts dependency.lohi-ts Vite plugin wired into vite.config.ts for Wasm optimization.src/infra/lohi/client.ts and a standard OSDK client factory in src/infra/osdk/client.ts, both sharing a single OAuth client from src/infra/auth/oauth.ts. Lohi is the default client, so reads and writes from @osdk/react hooks pass through the local cache, with writes applied optimistically.SyncProvider that runs an initial sync on mount, invalidates the OSDK cache after each successful sync, and can sync periodically in the background, paired with a <SyncGate> component that withholds the interface until the first sync completes.<StandardClientScope> and the useOnlineAction hook run an action against the standard client, then re-sync and invalidate the cache.You can use the tag version feature in a Foundry VS Code workspace or code repository to create a version tag for your application’s release.

You can also deploy your application using git tags if you are working offline:
Copied!1 2git tag 1.0.0 git push origin tag 1.0.0
Code Repositories will automatically build and deploy your application to the configured subdomain. For more details on deployment options, refer to Deploy a custom application on Foundry.
Once your application is deployed, users can install it as a progressive web app for offline access and a native-like experience.
Navigate to your deployed application in a supported browser. This includes Chrome, Edge, Safari, or other Chromium-based browsers.
Look for the Install or Add to Home Screen prompt:
Select Install and follow the browser's prompts.
The application will be installed and can be launched from your device like a native application.
After installation, you can launch the application from your installed apps or home screen. The application will work offline using synced Ontology data. When connectivity is restored, the application will automatically sync the latest data. Users can continue working with local data even without network access.
Only the Ontology objects configured in syncedObjectTypes will be available offline. Ensure that you have configured the appropriate objects before users install the application.
By default, every time the embedded Ontology syncs data (via lohi-ts) from remote Foundry, it will load all objects for the configured object types. This can be very slow, depending on the amount of data loading. You can turn on peering mode for your object types, which will only sync diffs from the previous sync and significantly speed up periodic data syncs.
In Ontology Manager, enable Offline App Sync for each configured object type:
Navigate to the Capabilities tab.

Enable Offline App Sync mode.

In the Datasources tab, wait until the Peering objects database successfully indexes your object type. This database is the backend service for the Ontology to which you are connected through peering.

In src/syncConfig.ts, set the per-type peering option on the relevant entries in syncedObjectTypes. Entries already use the lohi-ts SyncConfigParam type, which supports enabling peering per object type. See lohi-ts's documentation for more details.
Ensure that your Foundry enrollment allows CORS for the following:
http://localhost:8080Configure CORS in Control Panel if you have permission, or contact your Foundry administrator.
If you see build errors related to the dev-dist directory, delete the directory. This directory is automatically generated and is already included in the .gitignore.