diff --git a/src/instrumentation.ts b/src/instrumentation.ts index 0aea0b2fe..20e08db29 100644 --- a/src/instrumentation.ts +++ b/src/instrumentation.ts @@ -1,5 +1,20 @@ import type { Instrumentation } from "next"; +/** + * The admin notice for a host whose login-IP lookups leave it. The geo + * resolver evaluates it on its first public-IP lookup; it holds a slot + * rather than importing the notification layer (see the notice module). + */ +async function registerOfflineGeoNoticeAtBoot(): Promise { + try { + const { registerOfflineGeoNotice } = + await import("@/lib/notifications/offline-geo-notice"); + registerOfflineGeoNotice(); + } catch { + // Without it the lookups still resolve; only the notice is missing. + } +} + export async function register() { // Only start the worker on the Node.js server runtime (not Edge, not build) if (process.env.NEXT_RUNTIME === "nodejs") { @@ -35,16 +50,7 @@ export async function register() { // A readiness summary must never break boot. } - // The admin notice for a host whose login-IP lookups leave it. The geo - // resolver evaluates it on its first public-IP lookup; it holds a slot - // rather than importing the notification layer (see the notice module). - try { - const { registerOfflineGeoNotice } = - await import("@/lib/notifications/offline-geo-notice"); - registerOfflineGeoNotice(); - } catch { - // Without it the lookups still resolve; only the notice is missing. - } + await registerOfflineGeoNoticeAtBoot(); // Does the configured encryption key open this database? A process whose // key does not refuses every API request with one clear 503 and starts diff --git a/src/lib/__tests__/geo-offline-detection.test.ts b/src/lib/__tests__/geo-offline-detection.test.ts index aeea09d89..49e28ddb2 100644 --- a/src/lib/__tests__/geo-offline-detection.test.ts +++ b/src/lib/__tests__/geo-offline-detection.test.ts @@ -201,6 +201,11 @@ describe("offline-geo runtime detection", () => { expect(boot).toMatch( /import\("@\/lib\/notifications\/offline-geo-notice"\)[\s\S]*registerOfflineGeoNotice\(\)/, ); + // …and the helper that does it runs inside `register()`. + const registerBody = boot.slice( + boot.indexOf("export async function register()"), + ); + expect(registerBody).toContain("await registerOfflineGeoNoticeAtBoot()"); }); it("offlineGeoReady() is false when the .empty marker is present", async () => {