Initial props
The initial props pattern allows a Web Viewer app to retrieve bootstrap configuration from FileMaker Pro upon startup, such as user identity, active record IDs, or an initial route.
Use cases
FileMaker Pro and the Web Viewer maintain separate runtimes without shared memory. A web application cannot read FileMaker fields or global variables directly, and FileMaker cannot reliably inject values before JavaScript bundles finish loading. Initial props bridge this gap:
-
User identity at startup: Retrieve account names, user names, or privilege sets so the web interface can configure permissions before rendering.
-
Contextual routing: Open the Web Viewer to a specific screen depending on the originating layout or button.
-
Active record context: Retrieve the current record ID before the first render to load associated data immediately.
-
Eliminating race conditions: Avoid URL text-substitution techniques or layout script triggers that execute before the web app mounts.
Pull architecture
In this architecture, the Web Viewer pulls startup data from FileMaker Pro; FileMaker Pro does not push data unprompted.
When the web client mounts, it executes a FileMaker script using fmFetch and uses the returned JSON payload to complete bootstrapping.
Warning Avoid pushing data from FileMaker: Do not attempt to initialize data by substituting values into the Web Viewer URL or calling Perform JavaScript in Web Viewer from OnLayoutEnter or OnRecordLoad script triggers. These approaches execute before the JavaScript bundle finishes loading and attaching event handlers, causing data loss.
A pull approach ensures that:
-
The JavaScript bundle has fully loaded and initialized.
-
The
window.FileMakerJavaScript interface is active and callable. -
All component message listeners are registered.
In the ADK template, fmFetch executes immediately upon loading before routes render. The router receives the resolved props in context, allowing the first screen to display user and record state without layout shifts or re-rendering.
Basic structure
const initialPropsSchema = z.object({
user: z.object({
id: z.string(),
name: z.string(),
email: z.email(),
}),
initialRoute: z.string().optional(),
});
type InitialProps = z.infer<typeof initialPropsSchema>;
export async function getInitialProps(): Promise<InitialProps> {
const result = await fmFetch("GetInitialProps");
return initialPropsSchema.parse(result);
}
In FileMaker Pro, the GetInitialProps script gathers required startup values and returns a JSON string using the Exit Script step. See Script calls for parameter conventions.
Note Validate script results using Zod or a compatible schema library to ensure type safety across the FileMaker boundary.
Example: initial route
When using a client-side router with hash history, you can set the initial route dynamically based on active FileMaker context:
const initialPropsSchema = z.object({
initialRoute: z.string().optional(),
});
const GET_INITIAL_PROPS_SCRIPT = "GetInitialProps";
export async function createAppRouter() {
const result = await fmFetch(GET_INITIAL_PROPS_SCRIPT);
const { initialRoute } = initialPropsSchema.parse(result);
if (initialRoute && !window.location.hash) {
window.location.hash = initialRoute;
}
return createRouter({
history: createHashHistory(),
routeTree,
});
}
If [ not IsEmpty ( Customers::id ) ]
Set Variable [ $route ; Value: "/customers/" & Customers::id ]
Else
Set Variable [ $route ; Value: "/" ]
End If
Set Variable [ $result ; Value: JSONSetElement ( "" ;
[ "initialRoute" ; $route ; JSONString ]
) ]
Exit Script [ Text Result: $result ]
Checking window.location.hash prevents the router from resetting an in-progress user session if the Web Viewer reloads.
Example: user identity
Pass current account credentials to the app to adapt interface elements:
export const initialPropsSchema = z.object({
user: z.object({
accountName: z.string(),
fullName: z.string(),
privilegeSet: z.string(),
}),
});
export type InitialProps = z.infer<typeof initialPropsSchema>;
export async function fetchInitialProps(): Promise<InitialProps> {
const result = await fmFetch("GetInitialProps");
return initialPropsSchema.parse(result);
}
Set Variable [ $result ; Value: JSONSetElement ( "" ;
[ "user.accountName" ; Get ( AccountName ) ; JSONString ] ;
[ "user.fullName" ; Get ( UserName ) ; JSONString ] ;
[ "user.privilegeSet" ; Get ( AccountPrivilegeSetName ) ; JSONString ]
) ]
Exit Script [ Text Result: $result ]
In the root React component, suspend rendering until initial props resolve:
const propsPromise = fetchInitialProps();
function Boot() {
const props = React.use(propsPromise);
return <App initialProps={props} />;
}
ReactDOM.createRoot(document.querySelector("#root")!).render(
<React.StrictMode>
<React.Suspense fallback={<div>Loading…</div>}>
<Boot />
</React.Suspense>
</React.StrictMode>,
);
When to use other patterns
Initial props are designed for one-time startup initialization. If data changes while the Web Viewer remains open (such as record changes in FileMaker), use one of the following approaches:
-
A fresh query using
fmFetchtriggered by client action. -
A FileMaker command using
Perform JavaScript in Web Viewerafter the initial bootstrap sequence finishes.