Skip to content

Function: isSSRStub() ​

ts
function isSSRStub(value: any): boolean;

Determines if a given value is an SSR stub implementation.

Parameters ​

ParameterTypeDescription
valueanyThe value to check for SSR stub status

Returns ​

boolean

True if the value is an SSR stub, false otherwise

Remarks ​

SSR stubs are special implementations used during Server-Side Rendering that mimic the behavior of real ReactiveRecord objects without performing actual database operations. All SSR stub implementations are marked with a $_is_stub property set to true.

This function is useful for:

  • Conditional logic based on SSR vs. browser environment
  • Testing and debugging SSR behavior
  • Implementing different code paths for stub vs. real implementations

Examples ​

typescript
import { useReActiveModel, isSSRStub } from "@nhtio/vue-re-active-record";

const User = useReActiveModel("user");

if (isSSRStub(User)) {
  console.log("Running in SSR mode with stub implementation");
  // Handle SSR-specific logic
} else {
  console.log("Running in browser with real database");
  // Handle browser-specific logic
}
typescript
// Check if a query result is from SSR stub
const query = User.query();
const result = await query.fetch();

if (isSSRStub(result)) {
  // Result is from SSR stub (empty array)
  console.log("SSR stub result:", result); // []
} else {
  // Result is from real database
  console.log("Real database result:", result);
}

See ​

isWebContext for environment detection