Skip to the content

Capsid menu

app/lib/context.ts

19 lines and 3 functions in DrDustinEdwards/carrel, at commit d5d5e82 on 2026-10-24. This file on GitHub.

Functions

The functions of context.ts
FunctionLinesComplexityCoveredCRAPMutation
getNonce16 to 1810%OkCRAP 2No data: mutation testing has not run on this repo yet
getEnv20 to 221100%OkCRAP 1No data: mutation testing has not run on this repo yet
getViewer24 to 261100%OkCRAP 1No data: mutation testing has not run on this repo yet

Imports

It imports app/lib/people.server.ts. Imported by app/entry.server.tsx, app/root.tsx, app/routes/ai-draft.preview.ts, app/routes/ai-draft.tsx, app/routes/auth.google.ts, app/routes/book.authorship.ts, app/routes/book.chapter.tsx, app/routes/book.corkboard.tsx, app/routes/book.export.ts, app/routes/book.file.tsx, app/routes/book.history.tsx, app/routes/book.new.tsx, app/routes/book.outliner.tsx, app/routes/book.tsx, app/routes/editor.tsx, app/routes/frame.tsx, app/routes/health.ts, app/routes/history.tsx, app/routes/home.tsx, app/routes/legal.tsx, app/routes/manuscripts.tsx, app/routes/media.api.ts, app/routes/media.bulk.ts, app/routes/media.tsx, app/routes/mentions.api.ts, app/routes/mentions.tsx, app/routes/people.tsx, app/routes/preview.ts, app/routes/project.bulk.ts, app/routes/project.flags.tsx, app/routes/project.new.tsx, app/routes/project.tsx, app/routes/project.voice.tsx, app/routes/social.tsx, app/routes/unpublish.tsx, workers/app.ts.

Source

import { createContext, type RouterContextProvider } from "react-router";

import type { Viewer } from "~/lib/people.server";

export const cloudflareContext = createContext<{ env: Env; ctx: ExecutionContext }>();

/** Set by the gate before any route runs. A route never sees a request without one. */
export const viewerContext = createContext<Viewer>();

/**
 * This render's CSP nonce. It must exist before the render: the same value goes in the header and on
 * every <script>. Set by workers/app.ts; the root loader hands it to Layout.
 */
export const nonceContext = createContext<string>();

export function getNonce(context: Readonly<RouterContextProvider>): string {
  return context.get(nonceContext);
}

export function getEnv(context: Readonly<RouterContextProvider>): Env {
  return context.get(cloudflareContext).env;
}

export function getViewer(context: Readonly<RouterContextProvider>): Viewer {
  return context.get(viewerContext);
}