Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
@@ -1,15 +1,14 @@
|
||||
import { initSentryServer } from "./sentry.server";
|
||||
import { startCacheSubscribers } from "./cache-bootstrap.server";
|
||||
import { startEntryRuntimeServices } from "./entry-runtime-bootstrap.server";
|
||||
|
||||
// IMPORTANT: Initialize Sentry as the very first action on the server
|
||||
// entry so the SDK can hook into the Node runtime (HTTP, async hooks)
|
||||
// before any other module runs. No-op when SENTRY_DSN_WEB is unset.
|
||||
initSentryServer();
|
||||
|
||||
// Start cross-replica cache-invalidation subscribers. Idempotent + safe
|
||||
// in single-replica deployments (no-op when REDIS_URL is unset thanks to
|
||||
// SharedStore memory fallback). See docs/architecture/two-tier-cache.md.
|
||||
startCacheSubscribers();
|
||||
// Vite resolves this import to a surface-specific boot module. Core keeps its
|
||||
// cache subscribers, while the Portal artifact never imports that Core graph.
|
||||
startEntryRuntimeServices();
|
||||
|
||||
import type { AppLoadContext, EntryContext } from "react-router";
|
||||
|
||||
@@ -20,15 +19,15 @@ import { ServerRouter } from "react-router";
|
||||
import { createReadableStreamFromReadable } from "@react-router/node";
|
||||
import { renderToPipeableStream } from "react-dom/server";
|
||||
|
||||
import Backend from "i18next-fs-backend";
|
||||
import { createInstance } from "i18next";
|
||||
import { I18nextProvider, initReactI18next } from "react-i18next";
|
||||
import { remixI18Next, serverLocalePath } from "./locale/i18next.server";
|
||||
import { remixI18Next } from "./locale/i18next.server";
|
||||
import { i18nConfig } from "./locale/i18n";
|
||||
import { syncServerGlobalI18nLanguage } from "./locale/i18next.global.server";
|
||||
import { getServerI18nResourcesSnapshot, getServerRequestI18nLanguage, runWithServerI18nLanguage } from "./locale/i18next.global.server";
|
||||
import { routes as otherRoutes } from "./other-routes.server";
|
||||
import { createScopedLogger } from "./utils/logger.server";
|
||||
import { shouldNoindex, X_ROBOTS_TAG_NOINDEX } from "./utils/seo/noindex.server";
|
||||
import { getRequestCspNonce } from "./utils/security/contentSecurityPolicy";
|
||||
|
||||
const ssrLogger = createScopedLogger("ssr.entry");
|
||||
|
||||
@@ -36,12 +35,33 @@ const ssrLogger = createScopedLogger("ssr.entry");
|
||||
// Reject/cancel all pending promises after 5 seconds
|
||||
export const streamTimeout = 5000;
|
||||
|
||||
export default async function handleRequest(
|
||||
export async function runWithRequestI18nScope<T>(request: Request, callback: () => T | Promise<T>): Promise<T> {
|
||||
const language = await remixI18Next.getLocale(request);
|
||||
return runWithServerI18nLanguage(language, callback);
|
||||
}
|
||||
|
||||
export default function handleRequest(
|
||||
request: Request,
|
||||
responseStatusCode: number,
|
||||
responseHeaders: Headers,
|
||||
reactRouterContext: EntryContext,
|
||||
loadContext: AppLoadContext
|
||||
) {
|
||||
if (getServerRequestI18nLanguage()) {
|
||||
return handleRequestWithinI18nScope(request, responseStatusCode, responseHeaders, reactRouterContext, loadContext);
|
||||
}
|
||||
|
||||
// The production server wraps React Router before loaders/actions execute.
|
||||
// Keep this entry-level fallback for development servers and direct tests.
|
||||
return runWithRequestI18nScope(request, () => handleRequestWithinI18nScope(request, responseStatusCode, responseHeaders, reactRouterContext, loadContext));
|
||||
}
|
||||
|
||||
async function handleRequestWithinI18nScope(
|
||||
request: Request,
|
||||
responseStatusCode: number,
|
||||
responseHeaders: Headers,
|
||||
reactRouterContext: EntryContext,
|
||||
_loadContext: AppLoadContext
|
||||
) {
|
||||
const callbackName = isbot(request.headers.get("user-agent")) ? "onAllReady" : "onShellReady";
|
||||
|
||||
@@ -53,42 +73,38 @@ export default async function handleRequest(
|
||||
|
||||
// Internationalization (i18n).
|
||||
const i18nInstance = createInstance();
|
||||
const lng = await remixI18Next.getLocale(request);
|
||||
const lng = getServerRequestI18nLanguage() ?? (await remixI18Next.getLocale(request));
|
||||
const ns = remixI18Next.getRouteNamespaces(reactRouterContext);
|
||||
const resources = getServerI18nResourcesSnapshot();
|
||||
const cspNonce = getRequestCspNonce(request);
|
||||
|
||||
await i18nInstance
|
||||
.use(initReactI18next) // Tell our instance to use react-i18next.
|
||||
.use(Backend) // Setup backend.
|
||||
.init({
|
||||
...i18nConfig, // Spread configuration.
|
||||
lng, // Locale detected above.
|
||||
ns, // Namespaces detected above.
|
||||
backend: {
|
||||
localePath: serverLocalePath,
|
||||
loadPath: `${serverLocalePath}/{{lng}}/{{ns}}.json`,
|
||||
},
|
||||
resources,
|
||||
// The process snapshot is already in memory; avoid scheduling another
|
||||
// async initialization turn for every SSR request.
|
||||
initImmediate: false,
|
||||
});
|
||||
|
||||
// Align the *global* i18next instance with the request locale so components
|
||||
// that resolve strings through the module-level `t` helper (rather than the
|
||||
// `useTranslation()` hook) render the same text the client hydrates with.
|
||||
// See ./locale/i18next.global.server.ts for the rationale.
|
||||
await syncServerGlobalI18nLanguage(lng);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
let shellRendered = false;
|
||||
|
||||
const { pipe, abort } = renderToPipeableStream(
|
||||
<I18nextProvider i18n={i18nInstance}>
|
||||
<ServerRouter context={reactRouterContext} url={request.url} />
|
||||
<ServerRouter context={reactRouterContext} url={request.url} nonce={cspNonce} />
|
||||
</I18nextProvider>,
|
||||
{
|
||||
nonce: cspNonce,
|
||||
[callbackName]: () => {
|
||||
shellRendered = true;
|
||||
const body = new PassThrough();
|
||||
const stream = createReadableStreamFromReadable(body);
|
||||
|
||||
responseHeaders.set("Content-Type", "text/html");
|
||||
responseHeaders.set("Content-Type", "text/html; charset=utf-8");
|
||||
// Default HTML responses to `no-store` so CDNs / browsers do not
|
||||
// cache rendered documents that may contain per-user data (CSRF
|
||||
// tokens, session-derived markup, feature flags). Loaders that
|
||||
|
||||
Reference in new issue
Block a user