mirror of
https://github.com/lobehub/lobehub.git
synced 2026-09-20 04:56:13 +08:00
12fa88e49a
* ♻️ refactor(auth): make the auth shell safe to prerender Three changes, all behaviour-preserving for the current client-rendered auth SPA, that a prerendered copy of the same pages needs: - `enableBusinessFeatures` is a build-time constant, not deployment state. `AuthServerConfigProvider` now reads it from `@lobechat/business-const` instead of the injected server config, so a render that has not received that config yet still resolves the right SSO provider source. - The terms checkbox and the "last used" provider both seeded `useState` from `localStorage` during render. A returning user's stored value makes the first render depend on the browser, which cannot be prerendered; they now start empty and fill in from an effect. - `LobeAnalyticsProviderWrapper` accepts the analytics config as a prop and guards its `window` read, so it can render outside a browser. Also drops the `@/features/AuthShell` barrel from the `src/features/Auth` importers: the barrel re-exports `AuthShell`, which pulls `AuthLocale` and the full en-US dictionary into every consumer's graph. * ✨ feat(auth): split the auth surface into a prerendered micro app `apps/auth` renders the sign-in flow ahead of time instead of shipping an empty `#root`. React Router framework mode with `ssr: false` + `prerender`, so the worker carries no React at all — 7KB, it picks one prerendered document by locale and swaps in the deployment's config. - 18 locales x 4 routes = 72 documents, plus a SPA fallback for the routes that take params. One build pass per locale writes the same canonical paths; the non-default passes are folded into `build/client/__i18n/`. Passes are independent, so they run 6 at a time (3m05s -> 44s). - Each document inlines only its own locale's dictionary; the rest load on demand for the language switcher, which keeps them off the first-load path entirely. - `/webapi/auth/spa-config` is a new public endpoint the worker reads to fill `window.__SERVER_CONFIG__`. It carries only the six fields the auth pages actually read; a failed lookup leaves the placeholder and the page still renders. - Per-route SEO: real localized titles, and `noindex, nofollow` on every transactional page — only /signin and /signup stay indexable, with a canonical URL. The existing Next.js `/spa-auth` route is untouched, so self-hosted and Docker deployments keep serving the client-rendered SPA. This app builds and deploys from lobehub-cloud, which overlays `@/business/*`. * 🐛 fix(auth): restore feature flags and track the prerender lib
51 lines
1.4 KiB
TypeScript
51 lines
1.4 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
|
|
import {
|
|
DEFAULT_PRERENDER_LOCALE,
|
|
documentPathFor,
|
|
PRERENDER_LOCALES,
|
|
PRERENDER_ROUTES,
|
|
resolveDocumentLocale,
|
|
SPA_FALLBACK_DOCUMENT,
|
|
} from './prerender';
|
|
|
|
describe('documentPathFor', () => {
|
|
it('serves the default-locale document at the canonical path', () => {
|
|
expect(documentPathFor('/signin', DEFAULT_PRERENDER_LOCALE)).toBe('/signin/index.html');
|
|
});
|
|
|
|
it('serves other locales from the folded i18n tree', () => {
|
|
expect(documentPathFor('/signup', 'zh-CN')).toBe('/__i18n/zh-CN/signup/index.html');
|
|
});
|
|
|
|
it('falls back to the SPA shell for param routes', () => {
|
|
expect(documentPathFor('/oauth/consent/abc', 'ja-JP')).toBe(SPA_FALLBACK_DOCUMENT);
|
|
});
|
|
});
|
|
|
|
describe('resolveDocumentLocale', () => {
|
|
it('keeps a prerendered locale', () => {
|
|
expect(resolveDocumentLocale('ja-JP')).toBe('ja-JP');
|
|
});
|
|
|
|
it('falls back to the default locale when the request is unknown', () => {
|
|
expect(resolveDocumentLocale('klingon')).toBe(DEFAULT_PRERENDER_LOCALE);
|
|
});
|
|
});
|
|
|
|
describe('prerender matrix', () => {
|
|
it('prerenders the four static auth routes', () => {
|
|
expect([...PRERENDER_ROUTES]).toEqual([
|
|
'/signin',
|
|
'/signup',
|
|
'/verify-email',
|
|
'/reset-password',
|
|
]);
|
|
});
|
|
|
|
it('covers every locale that ships auth dictionaries', () => {
|
|
expect(PRERENDER_LOCALES).toHaveLength(18);
|
|
expect(PRERENDER_LOCALES).toContain(DEFAULT_PRERENDER_LOCALE);
|
|
});
|
|
});
|