@alepha/react 0.14.4 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -0
- package/dist/auth/index.d.ts +4 -4
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/index.js +22 -31
- package/dist/auth/index.js.map +1 -1
- package/dist/core/index.d.ts +118 -118
- package/dist/core/index.d.ts.map +1 -1
- package/dist/form/index.d.ts +27 -28
- package/dist/form/index.d.ts.map +1 -1
- package/dist/head/index.d.ts +30 -40
- package/dist/head/index.d.ts.map +1 -1
- package/dist/i18n/index.d.ts +33 -33
- package/dist/i18n/index.d.ts.map +1 -1
- package/dist/router/index.d.ts +458 -458
- package/dist/router/index.d.ts.map +1 -1
- package/dist/router/index.js +22 -31
- package/dist/router/index.js.map +1 -1
- package/dist/websocket/index.d.ts +38 -39
- package/dist/websocket/index.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/auth/__tests__/$auth.spec.ts +10 -11
- package/src/router/providers/ReactServerProvider.ts +3 -13
- package/src/router/providers/ReactServerTemplateProvider.ts +47 -29
package/dist/router/index.d.ts
CHANGED
|
@@ -15,7 +15,6 @@ import { ServerStaticProvider } from "alepha/server/static";
|
|
|
15
15
|
import { ServerRouteCache } from "alepha/server/cache";
|
|
16
16
|
|
|
17
17
|
//#region ../../src/router/errors/Redirection.d.ts
|
|
18
|
-
|
|
19
18
|
/**
|
|
20
19
|
* Used for Redirection during the page loading.
|
|
21
20
|
*
|
|
@@ -70,10 +69,10 @@ declare class ReactPageProvider {
|
|
|
70
69
|
root(state: ReactRouterState): ReactNode;
|
|
71
70
|
protected convertStringObjectToObject: (schema?: TSchema, value?: any) => any;
|
|
72
71
|
/**
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
72
|
+
* Create a new RouterState based on a given route and request.
|
|
73
|
+
* This method resolves the layers for the route, applying any query and params schemas defined in the route.
|
|
74
|
+
* It also handles errors and redirects.
|
|
75
|
+
*/
|
|
77
76
|
createLayers(route: PageRoute, state: ReactRouterState, previous?: PreviousLayerData[]): Promise<CreateLayersResult>;
|
|
78
77
|
protected getErrorHandler(route: PageRoute): ErrorHandler | undefined;
|
|
79
78
|
protected createElement(page: PageRoute, props: Record<string, any>): Promise<ReactNode>;
|
|
@@ -99,9 +98,9 @@ interface PageRouteEntry extends Omit<PagePrimitiveOptions, "children" | "parent
|
|
|
99
98
|
}
|
|
100
99
|
interface ConcretePageRoute extends PageRoute {
|
|
101
100
|
/**
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
101
|
+
* When exported, static routes can be split into multiple pages with different params.
|
|
102
|
+
* We replace 'name' by the new name for each static entry, and old 'name' becomes 'staticName'.
|
|
103
|
+
*/
|
|
105
104
|
staticName?: string;
|
|
106
105
|
params?: Record<string, string>;
|
|
107
106
|
}
|
|
@@ -134,33 +133,33 @@ interface AnchorProps {
|
|
|
134
133
|
}
|
|
135
134
|
interface ReactRouterState {
|
|
136
135
|
/**
|
|
137
|
-
|
|
138
|
-
|
|
136
|
+
* Stack of layers for the current page.
|
|
137
|
+
*/
|
|
139
138
|
layers: Array<Layer>;
|
|
140
139
|
/**
|
|
141
|
-
|
|
142
|
-
|
|
140
|
+
* URL of the current page.
|
|
141
|
+
*/
|
|
143
142
|
url: URL;
|
|
144
143
|
/**
|
|
145
|
-
|
|
146
|
-
|
|
144
|
+
* Error handler for the current page.
|
|
145
|
+
*/
|
|
147
146
|
onError: ErrorHandler;
|
|
148
147
|
/**
|
|
149
|
-
|
|
150
|
-
|
|
148
|
+
* Params extracted from the URL for the current page.
|
|
149
|
+
*/
|
|
151
150
|
params: Record<string, any>;
|
|
152
151
|
/**
|
|
153
|
-
|
|
154
|
-
|
|
152
|
+
* Query parameters extracted from the URL for the current page.
|
|
153
|
+
*/
|
|
155
154
|
query: Record<string, string>;
|
|
156
155
|
/**
|
|
157
|
-
|
|
158
|
-
|
|
156
|
+
* Optional meta information associated with the current page.
|
|
157
|
+
*/
|
|
159
158
|
meta: Record<string, any>;
|
|
160
159
|
/**
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
160
|
+
* Head configuration for the current page (title, meta tags, etc.).
|
|
161
|
+
* Populated by HeadProvider during SSR.
|
|
162
|
+
*/
|
|
164
163
|
head: Head;
|
|
165
164
|
name?: string;
|
|
166
165
|
}
|
|
@@ -294,214 +293,214 @@ declare const $page: {
|
|
|
294
293
|
};
|
|
295
294
|
interface PagePrimitiveOptions<TConfig extends PageConfigSchema = PageConfigSchema, TProps extends object = TPropsDefault, TPropsParent extends object = TPropsParentDefault> {
|
|
296
295
|
/**
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
296
|
+
* Identifier name for the page. Must be unique.
|
|
297
|
+
*
|
|
298
|
+
* @default Primitive key
|
|
299
|
+
*/
|
|
301
300
|
name?: string;
|
|
302
301
|
/**
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
302
|
+
* Add a pathname to the page.
|
|
303
|
+
*
|
|
304
|
+
* Pathname can contain parameters, like `/post/:slug`.
|
|
305
|
+
*
|
|
306
|
+
* @default ""
|
|
307
|
+
*/
|
|
309
308
|
path?: string;
|
|
310
309
|
/**
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
310
|
+
* Add an input schema to define:
|
|
311
|
+
* - `params`: parameters from the pathname.
|
|
312
|
+
* - `query`: query parameters from the URL.
|
|
313
|
+
*/
|
|
315
314
|
schema?: TConfig;
|
|
316
315
|
/**
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
316
|
+
* Load data before rendering the page.
|
|
317
|
+
*
|
|
318
|
+
* This function receives
|
|
319
|
+
* - the request context (params, query, etc.)
|
|
320
|
+
* - the parent props (if page has a parent)
|
|
321
|
+
*
|
|
322
|
+
* > In SSR, the returned data will be serialized and sent to the client, then reused during the client-side hydration.
|
|
323
|
+
*
|
|
324
|
+
* Loader can be stopped by throwing an error, which will be handled by the `errorHandler` function.
|
|
325
|
+
* It's common to throw a `NotFoundError` to display a 404 page.
|
|
326
|
+
*
|
|
327
|
+
* RedirectError can be thrown to redirect the user to another page.
|
|
328
|
+
*/
|
|
330
329
|
loader?: (context: PageLoader<TConfig, TPropsParent>) => Async<TProps>;
|
|
331
330
|
/**
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
331
|
+
* Default props to pass to the component when rendering the page.
|
|
332
|
+
*
|
|
333
|
+
* Resolved props from the `resolve` function will override these default props.
|
|
334
|
+
*/
|
|
336
335
|
props?: () => Partial<TProps>;
|
|
337
336
|
/**
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
337
|
+
* The component to render when the page is loaded.
|
|
338
|
+
*
|
|
339
|
+
* If `lazy` is defined, this will be ignored.
|
|
340
|
+
* Prefer using `lazy` to improve the initial loading time.
|
|
341
|
+
*/
|
|
343
342
|
component?: FC<TProps & TPropsParent>;
|
|
344
343
|
/**
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
344
|
+
* Lazy load the component when the page is loaded.
|
|
345
|
+
*
|
|
346
|
+
* It's recommended to use this for components to improve the initial loading time
|
|
347
|
+
* and enable code-splitting.
|
|
348
|
+
*/
|
|
350
349
|
lazy?: () => Promise<{
|
|
351
350
|
default: FC<TProps & TPropsParent>;
|
|
352
351
|
}>;
|
|
353
352
|
/**
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
353
|
+
* Attach child pages to create nested routes.
|
|
354
|
+
* This will make the page a parent route.
|
|
355
|
+
*/
|
|
357
356
|
children?: Array<PagePrimitive> | (() => Array<PagePrimitive>);
|
|
358
357
|
/**
|
|
359
|
-
|
|
360
|
-
|
|
358
|
+
* Define a parent page for nested routing.
|
|
359
|
+
*/
|
|
361
360
|
parent?: PagePrimitive<PageConfigSchema, TPropsParent, any>;
|
|
362
361
|
/**
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
362
|
+
* Function to determine if the page can be accessed.
|
|
363
|
+
*
|
|
364
|
+
* If it returns false, the page will not be accessible and a 403 Forbidden error will be returned.
|
|
365
|
+
* This function can be used to implement permission-based access control.
|
|
366
|
+
*/
|
|
368
367
|
can?: () => boolean;
|
|
369
368
|
/**
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
369
|
+
* Catch any error from the `loader` function or during `rendering`.
|
|
370
|
+
*
|
|
371
|
+
* Expected to return one of the following:
|
|
372
|
+
* - a ReactNode to render an error page
|
|
373
|
+
* - a Redirection to redirect the user
|
|
374
|
+
* - undefined to let the error propagate
|
|
375
|
+
*
|
|
376
|
+
* If not defined, the error will be thrown and handled by the server or client error handler.
|
|
377
|
+
* If a leaf $page does not define an error handler, the error can be caught by parent pages.
|
|
378
|
+
*
|
|
379
|
+
* @example Catch a 404 from API and render a custom not found component:
|
|
380
|
+
* ```ts
|
|
381
|
+
* loader: async ({ params, query }) => {
|
|
382
|
+
* api.fetch("/api/resource", { params, query });
|
|
383
|
+
* },
|
|
384
|
+
* errorHandler: (error, context) => {
|
|
385
|
+
* if (HttpError.is(error, 404)) {
|
|
386
|
+
* return <ResourceNotFound />;
|
|
387
|
+
* }
|
|
388
|
+
* }
|
|
389
|
+
* ```
|
|
390
|
+
*
|
|
391
|
+
* @example Catch an 401 error and redirect the user to the login page:
|
|
392
|
+
* ```ts
|
|
393
|
+
* loader: async ({ params, query }) => {
|
|
394
|
+
* // but the user is not authenticated
|
|
395
|
+
* api.fetch("/api/resource", { params, query });
|
|
396
|
+
* },
|
|
397
|
+
* errorHandler: (error, context) => {
|
|
398
|
+
* if (HttpError.is(error, 401)) {
|
|
399
|
+
* // throwing a Redirection is also valid!
|
|
400
|
+
* return new Redirection("/login");
|
|
401
|
+
* }
|
|
402
|
+
* }
|
|
403
|
+
* ```
|
|
404
|
+
*/
|
|
406
405
|
errorHandler?: ErrorHandler;
|
|
407
406
|
/**
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
407
|
+
* If true, the page will be considered as a static page, immutable and cacheable.
|
|
408
|
+
* Replace boolean by an object to define static entries. (e.g. list of params/query)
|
|
409
|
+
*
|
|
410
|
+
* Browser-side: it only works with `alepha/vite`, which can pre-render the page at build time.
|
|
411
|
+
*
|
|
412
|
+
* Server-side: It will act as timeless cached page. You can use `cache` to configure the cache behavior.
|
|
413
|
+
*/
|
|
415
414
|
static?: boolean | {
|
|
416
415
|
entries?: Array<Partial<PageRequestConfig<TConfig>>>;
|
|
417
416
|
};
|
|
418
417
|
cache?: ServerRouteCache;
|
|
419
418
|
/**
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
419
|
+
* If true, force the page to be rendered only on the client-side (browser).
|
|
420
|
+
* It uses the `<ClientOnly/>` component to render the page.
|
|
421
|
+
*/
|
|
423
422
|
client?: boolean | ClientOnlyProps;
|
|
424
423
|
/**
|
|
425
|
-
|
|
426
|
-
|
|
424
|
+
* Called before the server response is sent to the client. (server only)
|
|
425
|
+
*/
|
|
427
426
|
onServerResponse?: (request: ServerRequest) => unknown;
|
|
428
427
|
/**
|
|
429
|
-
|
|
430
|
-
|
|
428
|
+
* Called when user leaves the page. (browser only)
|
|
429
|
+
*/
|
|
431
430
|
onLeave?: () => void;
|
|
432
431
|
/**
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
432
|
+
* @experimental
|
|
433
|
+
*
|
|
434
|
+
* Add a css animation when the page is loaded or unloaded.
|
|
435
|
+
* It uses CSS animations, so you need to define the keyframes in your CSS.
|
|
436
|
+
*
|
|
437
|
+
* @example Simple animation name
|
|
438
|
+
* ```ts
|
|
439
|
+
* animation: "fadeIn"
|
|
440
|
+
* ```
|
|
441
|
+
*
|
|
442
|
+
* CSS example:
|
|
443
|
+
* ```css
|
|
444
|
+
* @keyframes fadeIn {
|
|
445
|
+
* from { opacity: 0; }
|
|
446
|
+
* to { opacity: 1; }
|
|
447
|
+
* }
|
|
448
|
+
* ```
|
|
449
|
+
*
|
|
450
|
+
* @example Detailed animation
|
|
451
|
+
* ```ts
|
|
452
|
+
* animation: {
|
|
453
|
+
* enter: { name: "fadeIn", duration: 300 },
|
|
454
|
+
* exit: { name: "fadeOut", duration: 200, timing: "ease-in-out" },
|
|
455
|
+
* }
|
|
456
|
+
* ```
|
|
457
|
+
*
|
|
458
|
+
* @example Only exit animation
|
|
459
|
+
* ```ts
|
|
460
|
+
* animation: {
|
|
461
|
+
* exit: "fadeOut"
|
|
462
|
+
* }
|
|
463
|
+
* ```
|
|
464
|
+
*
|
|
465
|
+
* @example With custom timing function
|
|
466
|
+
* ```ts
|
|
467
|
+
* animation: {
|
|
468
|
+
* enter: { name: "fadeIn", duration: 300, timing: "cubic-bezier(0.4, 0, 0.2, 1)" },
|
|
469
|
+
* exit: { name: "fadeOut", duration: 200, timing: "ease-in-out" },
|
|
470
|
+
* }
|
|
471
|
+
* ```
|
|
472
|
+
*/
|
|
474
473
|
animation?: PageAnimation;
|
|
475
474
|
/**
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
475
|
+
* Head configuration for the page (title, meta tags, etc.).
|
|
476
|
+
*
|
|
477
|
+
* Can be a static object or a function that receives resolved props.
|
|
478
|
+
*
|
|
479
|
+
* @example Static head
|
|
480
|
+
* ```ts
|
|
481
|
+
* head: {
|
|
482
|
+
* title: "My Page",
|
|
483
|
+
* description: "Page description",
|
|
484
|
+
* }
|
|
485
|
+
* ```
|
|
486
|
+
*
|
|
487
|
+
* @example Dynamic head based on props
|
|
488
|
+
* ```ts
|
|
489
|
+
* head: (props) => ({
|
|
490
|
+
* title: props.user.name,
|
|
491
|
+
* description: `Profile of ${props.user.name}`,
|
|
492
|
+
* })
|
|
493
|
+
* ```
|
|
494
|
+
*/
|
|
496
495
|
head?: Head | ((props: TProps, previous?: Head) => Head);
|
|
497
496
|
/**
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
497
|
+
* Source path for SSR module preloading.
|
|
498
|
+
*
|
|
499
|
+
* This is automatically injected by the viteAlephaPreload plugin.
|
|
500
|
+
* It maps to the source file path used in Vite's SSR manifest.
|
|
501
|
+
*
|
|
502
|
+
* @internal
|
|
503
|
+
*/
|
|
505
504
|
[PAGE_PRELOAD_KEY]?: string;
|
|
506
505
|
}
|
|
507
506
|
type ErrorHandler = (error: Error, state: ReactRouterState) => ReactNode | Redirection | undefined;
|
|
@@ -510,11 +509,11 @@ declare class PagePrimitive<TConfig extends PageConfigSchema = PageConfigSchema,
|
|
|
510
509
|
protected onInit(): void;
|
|
511
510
|
get name(): string;
|
|
512
511
|
/**
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
512
|
+
* For testing or build purposes.
|
|
513
|
+
*
|
|
514
|
+
* This will render the page (HTML layout included or not) and return the HTML + context.
|
|
515
|
+
* Only valid for server-side rendering, it will throw an error if called on the client-side.
|
|
516
|
+
*/
|
|
518
517
|
render(options?: PagePrimitiveRenderOptions): Promise<PagePrimitiveRenderResult>;
|
|
519
518
|
fetch(options?: PagePrimitiveRenderOptions): Promise<{
|
|
520
519
|
html: string;
|
|
@@ -533,11 +532,11 @@ interface PagePrimitiveRenderOptions {
|
|
|
533
532
|
params?: Record<string, string>;
|
|
534
533
|
query?: Record<string, string>;
|
|
535
534
|
/**
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
535
|
+
* If true, the HTML layout will be included in the response.
|
|
536
|
+
* If false, only the page content will be returned.
|
|
537
|
+
*
|
|
538
|
+
* @default true
|
|
539
|
+
*/
|
|
541
540
|
html?: boolean;
|
|
542
541
|
hydration?: boolean;
|
|
543
542
|
}
|
|
@@ -588,8 +587,8 @@ interface RouterGoOptions {
|
|
|
588
587
|
query?: Record<string, string>;
|
|
589
588
|
meta?: Record<string, any>;
|
|
590
589
|
/**
|
|
591
|
-
|
|
592
|
-
|
|
590
|
+
* Recreate the whole page, ignoring the current state.
|
|
591
|
+
*/
|
|
593
592
|
force?: boolean;
|
|
594
593
|
}
|
|
595
594
|
/**
|
|
@@ -616,9 +615,9 @@ declare class ReactRouter<T extends object> {
|
|
|
616
615
|
query?: Record<string, any>;
|
|
617
616
|
}): string;
|
|
618
617
|
/**
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
618
|
+
* Reload the current page.
|
|
619
|
+
* This is equivalent to calling `go()` with the current pathname and search.
|
|
620
|
+
*/
|
|
622
621
|
reload(): Promise<void>;
|
|
623
622
|
getURL(): URL;
|
|
624
623
|
get location(): Location;
|
|
@@ -634,15 +633,15 @@ declare class ReactRouter<T extends object> {
|
|
|
634
633
|
anchor(path: keyof VirtualRouter<T>, options?: RouterGoOptions): AnchorProps;
|
|
635
634
|
base(path: string): string;
|
|
636
635
|
/**
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
636
|
+
* Set query params.
|
|
637
|
+
*
|
|
638
|
+
* @param record
|
|
639
|
+
* @param options
|
|
640
|
+
*/
|
|
642
641
|
setQueryParams(record: Record<string, any> | ((queryParams: Record<string, any>) => Record<string, any>), options?: {
|
|
643
642
|
/**
|
|
644
|
-
|
|
645
|
-
|
|
643
|
+
* If true, this will add a new entry to the history stack.
|
|
644
|
+
*/
|
|
646
645
|
push?: boolean;
|
|
647
646
|
}): void;
|
|
648
647
|
}
|
|
@@ -679,16 +678,16 @@ declare class ReactBrowserProvider {
|
|
|
679
678
|
};
|
|
680
679
|
get state(): ReactRouterState;
|
|
681
680
|
/**
|
|
682
|
-
|
|
683
|
-
|
|
681
|
+
* Accessor for Document DOM API.
|
|
682
|
+
*/
|
|
684
683
|
get document(): Document;
|
|
685
684
|
/**
|
|
686
|
-
|
|
687
|
-
|
|
685
|
+
* Accessor for History DOM API.
|
|
686
|
+
*/
|
|
688
687
|
get history(): History;
|
|
689
688
|
/**
|
|
690
|
-
|
|
691
|
-
|
|
689
|
+
* Accessor for Location DOM API.
|
|
690
|
+
*/
|
|
692
691
|
get location(): Location;
|
|
693
692
|
get base(): string;
|
|
694
693
|
get url(): string;
|
|
@@ -697,8 +696,8 @@ declare class ReactBrowserProvider {
|
|
|
697
696
|
go(url: string, options?: RouterGoOptions): Promise<void>;
|
|
698
697
|
protected render(options?: RouterRenderOptions): Promise<void>;
|
|
699
698
|
/**
|
|
700
|
-
|
|
701
|
-
|
|
699
|
+
* Get embedded layers from the server.
|
|
700
|
+
*/
|
|
702
701
|
protected getHydrationState(): ReactHydrationState | undefined;
|
|
703
702
|
protected readonly onTransitionEnd: alepha1.HookPrimitive<"react:transition:end">;
|
|
704
703
|
readonly ready: alepha1.HookPrimitive<"ready">;
|
|
@@ -1115,94 +1114,94 @@ declare class ReactServerTemplateProvider {
|
|
|
1115
1114
|
protected readonly log: alepha_logger0.Logger;
|
|
1116
1115
|
protected readonly alepha: Alepha;
|
|
1117
1116
|
/**
|
|
1118
|
-
|
|
1119
|
-
|
|
1117
|
+
* Shared TextEncoder instance - reused across all requests.
|
|
1118
|
+
*/
|
|
1120
1119
|
protected readonly encoder: TextEncoder;
|
|
1121
1120
|
/**
|
|
1122
|
-
|
|
1123
|
-
|
|
1121
|
+
* Pre-encoded common strings for streaming.
|
|
1122
|
+
*/
|
|
1124
1123
|
protected readonly ENCODED: {
|
|
1125
1124
|
readonly HYDRATION_PREFIX: Uint8Array<ArrayBuffer>;
|
|
1126
1125
|
readonly HYDRATION_SUFFIX: Uint8Array<ArrayBuffer>;
|
|
1127
1126
|
readonly EMPTY: Uint8Array<ArrayBuffer>;
|
|
1128
1127
|
};
|
|
1129
1128
|
/**
|
|
1130
|
-
|
|
1131
|
-
|
|
1129
|
+
* Cached template slots - parsed once, reused for all requests.
|
|
1130
|
+
*/
|
|
1132
1131
|
protected slots: TemplateSlots | null;
|
|
1133
1132
|
/**
|
|
1134
|
-
|
|
1135
|
-
|
|
1133
|
+
* Root element ID for React mounting.
|
|
1134
|
+
*/
|
|
1136
1135
|
get rootId(): string;
|
|
1137
1136
|
/**
|
|
1138
|
-
|
|
1139
|
-
|
|
1137
|
+
* Regex pattern for matching the root div and extracting its content.
|
|
1138
|
+
*/
|
|
1140
1139
|
get rootDivRegex(): RegExp;
|
|
1141
1140
|
/**
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1141
|
+
* Extract the content inside the root div from HTML.
|
|
1142
|
+
*
|
|
1143
|
+
* @param html - Full HTML string
|
|
1144
|
+
* @returns The content inside the root div, or undefined if not found
|
|
1145
|
+
*/
|
|
1147
1146
|
extractRootContent(html: string): string | undefined;
|
|
1148
1147
|
/**
|
|
1149
|
-
|
|
1150
|
-
|
|
1148
|
+
* Check if template has been parsed and slots are available.
|
|
1149
|
+
*/
|
|
1151
1150
|
isReady(): boolean;
|
|
1152
1151
|
/**
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1152
|
+
* Get the parsed template slots.
|
|
1153
|
+
* Throws if template hasn't been parsed yet.
|
|
1154
|
+
*/
|
|
1156
1155
|
getSlots(): TemplateSlots;
|
|
1157
1156
|
/**
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1157
|
+
* Parse an HTML template into logical slots for efficient streaming.
|
|
1158
|
+
*
|
|
1159
|
+
* This should be called once during server startup/configuration.
|
|
1160
|
+
* The parsed slots are cached and reused for all requests.
|
|
1161
|
+
*
|
|
1162
|
+
* @param template - The HTML template string (typically index.html)
|
|
1163
|
+
*/
|
|
1165
1164
|
parseTemplate(template: string): TemplateSlots;
|
|
1166
1165
|
/**
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1166
|
+
* Parse HTML attributes string into a record.
|
|
1167
|
+
*
|
|
1168
|
+
* Handles: key="value", key='value', key=value, and boolean key
|
|
1169
|
+
*/
|
|
1171
1170
|
protected parseAttributes(attrStr: string): Record<string, string>;
|
|
1172
1171
|
/**
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1172
|
+
* Render attributes record to HTML string.
|
|
1173
|
+
*
|
|
1174
|
+
* @param attrs - Attributes to render
|
|
1175
|
+
* @returns HTML attribute string like ` lang="en" class="dark"`
|
|
1176
|
+
*/
|
|
1178
1177
|
renderAttributes(attrs: Record<string, string>): string;
|
|
1179
1178
|
/**
|
|
1180
|
-
|
|
1181
|
-
|
|
1179
|
+
* Render merged HTML attributes (original + dynamic).
|
|
1180
|
+
*/
|
|
1182
1181
|
renderMergedHtmlAttrs(dynamicAttrs?: Record<string, string>): string;
|
|
1183
1182
|
/**
|
|
1184
|
-
|
|
1185
|
-
|
|
1183
|
+
* Render merged body attributes (original + dynamic).
|
|
1184
|
+
*/
|
|
1186
1185
|
renderMergedBodyAttrs(dynamicAttrs?: Record<string, string>): string;
|
|
1187
1186
|
/**
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1187
|
+
* Render head content (title, meta, link, script tags).
|
|
1188
|
+
*
|
|
1189
|
+
* @param head - Head data to render
|
|
1190
|
+
* @param includeOriginal - Whether to include original head content
|
|
1191
|
+
* @returns HTML string with head content
|
|
1192
|
+
*/
|
|
1194
1193
|
renderHeadContent(head?: SimpleHead, includeOriginal?: boolean): string;
|
|
1195
1194
|
/**
|
|
1196
|
-
|
|
1197
|
-
|
|
1195
|
+
* Render a meta tag.
|
|
1196
|
+
*/
|
|
1198
1197
|
protected renderMetaTag(meta: {
|
|
1199
1198
|
name?: string;
|
|
1200
1199
|
property?: string;
|
|
1201
1200
|
content: string;
|
|
1202
1201
|
}): string;
|
|
1203
1202
|
/**
|
|
1204
|
-
|
|
1205
|
-
|
|
1203
|
+
* Render a link tag.
|
|
1204
|
+
*/
|
|
1206
1205
|
protected renderLinkTag(link: {
|
|
1207
1206
|
rel: string;
|
|
1208
1207
|
href: string;
|
|
@@ -1210,99 +1209,100 @@ declare class ReactServerTemplateProvider {
|
|
|
1210
1209
|
crossorigin?: string;
|
|
1211
1210
|
}): string;
|
|
1212
1211
|
/**
|
|
1213
|
-
|
|
1214
|
-
|
|
1212
|
+
* Render a script tag.
|
|
1213
|
+
*/
|
|
1215
1214
|
protected renderScriptTag(script: Record<string, string | boolean>): string;
|
|
1216
1215
|
/**
|
|
1217
|
-
|
|
1218
|
-
|
|
1216
|
+
* Escape HTML special characters.
|
|
1217
|
+
*/
|
|
1219
1218
|
escapeHtml(str: string): string;
|
|
1220
1219
|
/**
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1220
|
+
* Safely serialize data to JSON for embedding in HTML.
|
|
1221
|
+
* Escapes characters that could break out of script tags.
|
|
1222
|
+
*/
|
|
1224
1223
|
safeJsonSerialize(data: unknown): string;
|
|
1225
1224
|
/**
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1225
|
+
* Build hydration data from router state.
|
|
1226
|
+
*
|
|
1227
|
+
* This creates the data structure that will be serialized to window.__ssr
|
|
1228
|
+
* for client-side rehydration.
|
|
1229
|
+
*/
|
|
1231
1230
|
buildHydrationData(state: ReactRouterState): HydrationData;
|
|
1232
1231
|
/**
|
|
1233
|
-
|
|
1234
|
-
|
|
1232
|
+
* Encode a string to Uint8Array using the shared encoder.
|
|
1233
|
+
*/
|
|
1235
1234
|
encode(str: string): Uint8Array;
|
|
1236
1235
|
/**
|
|
1237
|
-
|
|
1238
|
-
|
|
1236
|
+
* Get the pre-encoded hydration script prefix.
|
|
1237
|
+
*/
|
|
1239
1238
|
get hydrationPrefix(): Uint8Array;
|
|
1240
1239
|
/**
|
|
1241
|
-
|
|
1242
|
-
|
|
1240
|
+
* Get the pre-encoded hydration script suffix.
|
|
1241
|
+
*/
|
|
1243
1242
|
get hydrationSuffix(): Uint8Array;
|
|
1244
1243
|
/**
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1244
|
+
* Create a ReadableStream that streams the HTML template with React content.
|
|
1245
|
+
*
|
|
1246
|
+
* This is the main entry point for SSR streaming. It:
|
|
1247
|
+
* 1. Sends <head> immediately (browser starts downloading assets)
|
|
1248
|
+
* 2. Streams React content as it renders
|
|
1249
|
+
* 3. Appends hydration script and closing tags
|
|
1250
|
+
*
|
|
1251
|
+
* @param reactStream - ReadableStream from renderToReadableStream
|
|
1252
|
+
* @param state - Router state with head data
|
|
1253
|
+
* @param options - Streaming options
|
|
1254
|
+
*/
|
|
1256
1255
|
createHtmlStream(reactStream: ReadableStream<Uint8Array>, state: ReactRouterState, options?: {
|
|
1257
1256
|
hydration?: boolean;
|
|
1258
1257
|
onError?: (error: unknown) => void;
|
|
1259
1258
|
}): ReadableStream<Uint8Array>;
|
|
1260
1259
|
/**
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1260
|
+
* Early head content for preloading.
|
|
1261
|
+
*
|
|
1262
|
+
* Contains entry assets (JS + CSS) that are always required and can be
|
|
1263
|
+
* sent before page loaders run.
|
|
1264
|
+
*/
|
|
1266
1265
|
protected earlyHeadContent: string;
|
|
1267
1266
|
/**
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1267
|
+
* Set the early head content (entry script + CSS).
|
|
1268
|
+
*
|
|
1269
|
+
* Also strips these assets from the original head content to avoid duplicates,
|
|
1270
|
+
* since we're moving them to the early phase.
|
|
1271
|
+
*
|
|
1272
|
+
* @param content - HTML string with entry assets
|
|
1273
|
+
* @param entryAssets - Entry asset paths to strip from original head
|
|
1274
|
+
*/
|
|
1276
1275
|
setEarlyHeadContent(content: string, entryAssets?: {
|
|
1277
1276
|
js?: string;
|
|
1278
1277
|
css: string[];
|
|
1279
1278
|
}): void;
|
|
1280
1279
|
/**
|
|
1281
|
-
|
|
1282
|
-
|
|
1280
|
+
* Escape special regex characters in a string.
|
|
1281
|
+
*/
|
|
1283
1282
|
protected escapeRegExp(str: string): string;
|
|
1284
1283
|
/**
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1284
|
+
* Create an optimized HTML stream with early head streaming.
|
|
1285
|
+
*
|
|
1286
|
+
* This version sends critical assets (entry.js, CSS) BEFORE page loaders run,
|
|
1287
|
+
* allowing the browser to start downloading them immediately.
|
|
1288
|
+
*
|
|
1289
|
+
* Flow:
|
|
1290
|
+
* 1. Send DOCTYPE, <html>, <head> open, entry preloads (IMMEDIATE)
|
|
1291
|
+
* 2. Run async work (createLayers, etc.)
|
|
1292
|
+
* 3. Send rest of head, body, React content, hydration
|
|
1293
|
+
*
|
|
1294
|
+
* @param globalHead - Global head with htmlAttributes (from $head primitives)
|
|
1295
|
+
* @param asyncWork - Async function to run between early head and rest of stream
|
|
1296
|
+
* @param options - Streaming options
|
|
1297
|
+
*/
|
|
1299
1298
|
createEarlyHtmlStream(globalHead: SimpleHead, asyncWork: () => Promise<{
|
|
1300
1299
|
state: ReactRouterState;
|
|
1301
1300
|
reactStream: ReadableStream<Uint8Array>;
|
|
1301
|
+
} | {
|
|
1302
|
+
redirect: string;
|
|
1302
1303
|
} | null>, options?: {
|
|
1303
1304
|
hydration?: boolean;
|
|
1304
1305
|
onError?: (error: unknown) => void;
|
|
1305
|
-
onRedirect?: (url: string) => void;
|
|
1306
1306
|
}): ReadableStream<Uint8Array>;
|
|
1307
1307
|
}
|
|
1308
1308
|
/**
|
|
@@ -1349,17 +1349,17 @@ interface HydrationData {
|
|
|
1349
1349
|
*/
|
|
1350
1350
|
declare const ssrManifestAtomSchema: alepha1.TObject<{
|
|
1351
1351
|
/**
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1352
|
+
* Preload manifest mapping short keys to source paths.
|
|
1353
|
+
* Generated by viteAlephaSsrPreload plugin at build time.
|
|
1354
|
+
*/
|
|
1355
1355
|
preload: alepha1.TOptional<alepha1.TRecord<"^.*$", alepha1.TString>>;
|
|
1356
1356
|
/**
|
|
1357
|
-
|
|
1358
|
-
|
|
1357
|
+
* SSR manifest mapping source files to their required chunks.
|
|
1358
|
+
*/
|
|
1359
1359
|
ssr: alepha1.TOptional<alepha1.TRecord<"^.*$", alepha1.TArray<alepha1.TString>>>;
|
|
1360
1360
|
/**
|
|
1361
|
-
|
|
1362
|
-
|
|
1361
|
+
* Client manifest mapping source files to their output information.
|
|
1362
|
+
*/
|
|
1363
1363
|
client: alepha1.TOptional<alepha1.TRecord<"^.*$", alepha1.TObject<{
|
|
1364
1364
|
file: alepha1.TString;
|
|
1365
1365
|
src: alepha1.TOptional<alepha1.TString>;
|
|
@@ -1392,45 +1392,45 @@ type SsrManifestAtomSchema = typeof ssrManifestAtomSchema;
|
|
|
1392
1392
|
declare class SSRManifestProvider {
|
|
1393
1393
|
protected readonly alepha: Alepha;
|
|
1394
1394
|
/**
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1395
|
+
* Get the manifest from the store at runtime.
|
|
1396
|
+
* This ensures the manifest is available even when set after module load.
|
|
1397
|
+
*/
|
|
1398
1398
|
protected get manifest(): Static<SsrManifestAtomSchema>;
|
|
1399
1399
|
/**
|
|
1400
|
-
|
|
1401
|
-
|
|
1400
|
+
* Get the preload manifest.
|
|
1401
|
+
*/
|
|
1402
1402
|
protected get preloadManifest(): PreloadManifest | undefined;
|
|
1403
1403
|
/**
|
|
1404
|
-
|
|
1405
|
-
|
|
1404
|
+
* Get the SSR manifest.
|
|
1405
|
+
*/
|
|
1406
1406
|
protected get ssrManifest(): SSRManifest | undefined;
|
|
1407
1407
|
/**
|
|
1408
|
-
|
|
1409
|
-
|
|
1408
|
+
* Get the client manifest.
|
|
1409
|
+
*/
|
|
1410
1410
|
protected get clientManifest(): ClientManifest | undefined;
|
|
1411
1411
|
/**
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1412
|
+
* Resolve a preload key to its source path.
|
|
1413
|
+
*
|
|
1414
|
+
* The key is a short hash injected by viteAlephaSsrPreload plugin,
|
|
1415
|
+
* which maps to the full source path in the preload manifest.
|
|
1416
|
+
*
|
|
1417
|
+
* @param key - Short hash key (e.g., "a1b2c3d4")
|
|
1418
|
+
* @returns Source path (e.g., "src/pages/UserDetail.tsx") or undefined
|
|
1419
|
+
*/
|
|
1420
1420
|
resolvePreloadKey(key: string): string | undefined;
|
|
1421
1421
|
/**
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1422
|
+
* Get all chunks required for a source file, including transitive dependencies.
|
|
1423
|
+
*
|
|
1424
|
+
* Uses the client manifest to recursively resolve all imported chunks,
|
|
1425
|
+
* not just the direct chunks from the SSR manifest.
|
|
1426
|
+
*
|
|
1427
|
+
* @param sourcePath - Source file path (e.g., "src/pages/Home.tsx")
|
|
1428
|
+
* @returns Array of chunk URLs to preload, or empty array if not found
|
|
1429
|
+
*/
|
|
1430
1430
|
getChunks(sourcePath: string): string[];
|
|
1431
1431
|
/**
|
|
1432
|
-
|
|
1433
|
-
|
|
1432
|
+
* Find manifest entry for a source path, trying different extensions.
|
|
1433
|
+
*/
|
|
1434
1434
|
protected findManifestEntry(sourcePath: string): {
|
|
1435
1435
|
file: string;
|
|
1436
1436
|
src?: string;
|
|
@@ -1442,16 +1442,16 @@ declare class SSRManifestProvider {
|
|
|
1442
1442
|
assets?: string[];
|
|
1443
1443
|
} | undefined;
|
|
1444
1444
|
/**
|
|
1445
|
-
|
|
1446
|
-
|
|
1445
|
+
* Recursively collect all chunk URLs for a manifest entry.
|
|
1446
|
+
*/
|
|
1447
1447
|
protected collectChunksRecursive(key: string, chunks: Set<string>, visited: Set<string>): void;
|
|
1448
1448
|
/**
|
|
1449
|
-
|
|
1450
|
-
|
|
1449
|
+
* Fallback to SSR manifest for chunk lookup.
|
|
1450
|
+
*/
|
|
1451
1451
|
protected getChunksFromSSRManifest(sourcePath: string): string[];
|
|
1452
1452
|
/**
|
|
1453
|
-
|
|
1454
|
-
|
|
1453
|
+
* Collect modulepreload links for a route and its parent chain.
|
|
1454
|
+
*/
|
|
1455
1455
|
collectPreloadLinks(route: PageRoute): Array<{
|
|
1456
1456
|
rel: string;
|
|
1457
1457
|
href: string;
|
|
@@ -1459,34 +1459,34 @@ declare class SSRManifestProvider {
|
|
|
1459
1459
|
crossorigin?: string;
|
|
1460
1460
|
}>;
|
|
1461
1461
|
/**
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1462
|
+
* Get all chunks for multiple source files.
|
|
1463
|
+
*
|
|
1464
|
+
* @param sourcePaths - Array of source file paths
|
|
1465
|
+
* @returns Deduplicated array of chunk URLs
|
|
1466
|
+
*/
|
|
1467
1467
|
getChunksForMultiple(sourcePaths: string[]): string[];
|
|
1468
1468
|
/**
|
|
1469
|
-
|
|
1470
|
-
|
|
1469
|
+
* Check if manifests are loaded and available.
|
|
1470
|
+
*/
|
|
1471
1471
|
isAvailable(): boolean;
|
|
1472
1472
|
/**
|
|
1473
|
-
|
|
1474
|
-
|
|
1473
|
+
* Cached entry assets - computed once at first access.
|
|
1474
|
+
*/
|
|
1475
1475
|
protected cachedEntryAssets: EntryAssets | null;
|
|
1476
1476
|
/**
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1477
|
+
* Get the entry point assets (main entry.js and associated CSS files).
|
|
1478
|
+
*
|
|
1479
|
+
* These assets are always required for all pages and can be preloaded
|
|
1480
|
+
* before page-specific loaders run.
|
|
1481
|
+
*
|
|
1482
|
+
* @returns Entry assets with js and css paths, or null if manifest unavailable
|
|
1483
|
+
*/
|
|
1484
1484
|
getEntryAssets(): EntryAssets | null;
|
|
1485
1485
|
/**
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1486
|
+
* Build preload link tags for entry assets.
|
|
1487
|
+
*
|
|
1488
|
+
* @returns Array of link objects ready to be rendered
|
|
1489
|
+
*/
|
|
1490
1490
|
getEntryPreloadLinks(): Array<{
|
|
1491
1491
|
rel: string;
|
|
1492
1492
|
href: string;
|
|
@@ -1544,8 +1544,8 @@ type PreloadManifest = Record<string, string>;
|
|
|
1544
1544
|
*/
|
|
1545
1545
|
declare class ReactServerProvider {
|
|
1546
1546
|
/**
|
|
1547
|
-
|
|
1548
|
-
|
|
1547
|
+
* SSR response headers - pre-allocated to avoid object creation per request.
|
|
1548
|
+
*/
|
|
1549
1549
|
protected readonly SSR_HEADERS: {
|
|
1550
1550
|
readonly "content-type": "text/html";
|
|
1551
1551
|
readonly "cache-control": "no-store, no-cache, must-revalidate, proxy-revalidate";
|
|
@@ -1566,8 +1566,8 @@ declare class ReactServerProvider {
|
|
|
1566
1566
|
protected readonly serverTimingProvider: ServerTimingProvider;
|
|
1567
1567
|
protected readonly ssrManifestProvider: SSRManifestProvider;
|
|
1568
1568
|
/**
|
|
1569
|
-
|
|
1570
|
-
|
|
1569
|
+
* Cached check for ServerLinksProvider - avoids has() lookup per request.
|
|
1570
|
+
*/
|
|
1571
1571
|
protected hasServerLinksProvider: boolean;
|
|
1572
1572
|
protected readonly options: Readonly<{
|
|
1573
1573
|
publicDir: string;
|
|
@@ -1577,75 +1577,75 @@ declare class ReactServerProvider {
|
|
|
1577
1577
|
};
|
|
1578
1578
|
}>;
|
|
1579
1579
|
/**
|
|
1580
|
-
|
|
1581
|
-
|
|
1580
|
+
* Configure the React server provider.
|
|
1581
|
+
*/
|
|
1582
1582
|
readonly onConfigure: alepha1.HookPrimitive<"configure">;
|
|
1583
1583
|
/**
|
|
1584
|
-
|
|
1585
|
-
|
|
1584
|
+
* Get the current HTML template.
|
|
1585
|
+
*/
|
|
1586
1586
|
get template(): string;
|
|
1587
1587
|
/**
|
|
1588
|
-
|
|
1589
|
-
|
|
1588
|
+
* Register all pages as server routes.
|
|
1589
|
+
*/
|
|
1590
1590
|
protected registerPages(templateLoader: TemplateLoader): Promise<void>;
|
|
1591
1591
|
/**
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1592
|
+
* Set up early head content with entry assets.
|
|
1593
|
+
*
|
|
1594
|
+
* This content is sent immediately when streaming starts, before page loaders run,
|
|
1595
|
+
* allowing the browser to start downloading entry.js and CSS files early.
|
|
1596
|
+
*
|
|
1597
|
+
* Uses <script type="module"> instead of <link rel="modulepreload"> for JS
|
|
1598
|
+
* because the script needs to execute anyway - this way the browser starts
|
|
1599
|
+
* downloading, parsing, AND will execute as soon as ready.
|
|
1600
|
+
*
|
|
1601
|
+
* Also strips these assets from the original template head to avoid duplicates.
|
|
1602
|
+
*/
|
|
1603
1603
|
protected setupEarlyHeadContent(): void;
|
|
1604
1604
|
/**
|
|
1605
|
-
|
|
1606
|
-
|
|
1605
|
+
* Get the public directory path where static files are located.
|
|
1606
|
+
*/
|
|
1607
1607
|
protected getPublicDirectory(): Promise<string>;
|
|
1608
1608
|
/**
|
|
1609
|
-
|
|
1610
|
-
|
|
1609
|
+
* Configure the static file server to serve files from the given root directory.
|
|
1610
|
+
*/
|
|
1611
1611
|
protected configureStaticServer(root: string): Promise<void>;
|
|
1612
1612
|
/**
|
|
1613
|
-
|
|
1614
|
-
|
|
1613
|
+
* Configure Vite for SSR in development mode.
|
|
1614
|
+
*/
|
|
1615
1615
|
protected configureVite(ssrEnabled: boolean): Promise<void>;
|
|
1616
1616
|
/**
|
|
1617
|
-
|
|
1618
|
-
|
|
1617
|
+
* Create the request handler for a page route.
|
|
1618
|
+
*/
|
|
1619
1619
|
protected createHandler(route: PageRoute, templateLoader: TemplateLoader): ServerHandler;
|
|
1620
1620
|
/**
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1621
|
+
* Core page rendering logic shared between SSR handler and static prerendering.
|
|
1622
|
+
*
|
|
1623
|
+
* Handles:
|
|
1624
|
+
* - Layer resolution (loaders)
|
|
1625
|
+
* - Redirect detection
|
|
1626
|
+
* - Head content filling
|
|
1627
|
+
* - Preload link collection
|
|
1628
|
+
* - React stream rendering
|
|
1629
|
+
*
|
|
1630
|
+
* @param route - The page route to render
|
|
1631
|
+
* @param state - The router state
|
|
1632
|
+
* @returns Render result with redirect or React stream
|
|
1633
|
+
*/
|
|
1634
1634
|
protected renderPage(route: PageRoute, state: ReactRouterState): Promise<{
|
|
1635
1635
|
redirect?: string;
|
|
1636
1636
|
reactStream?: ReadableStream<Uint8Array>;
|
|
1637
1637
|
}>;
|
|
1638
1638
|
/**
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1639
|
+
* For testing purposes, renders a page to HTML string.
|
|
1640
|
+
* Uses the same streaming code path as production, then collects to string.
|
|
1641
|
+
*
|
|
1642
|
+
* @param name - Page name to render
|
|
1643
|
+
* @param options - Render options (params, query, html, hydration)
|
|
1644
|
+
*/
|
|
1645
1645
|
render(name: string, options?: PagePrimitiveRenderOptions): Promise<PagePrimitiveRenderResult>;
|
|
1646
1646
|
/**
|
|
1647
|
-
|
|
1648
|
-
|
|
1647
|
+
* Collect a ReadableStream into a string.
|
|
1648
|
+
*/
|
|
1649
1649
|
protected streamToString(stream: ReadableStream<Uint8Array>): Promise<string>;
|
|
1650
1650
|
}
|
|
1651
1651
|
type TemplateLoader = () => Promise<string | undefined>;
|
|
@@ -1683,26 +1683,26 @@ declare module "alepha" {
|
|
|
1683
1683
|
}
|
|
1684
1684
|
interface Hooks {
|
|
1685
1685
|
/**
|
|
1686
|
-
|
|
1687
|
-
|
|
1686
|
+
* Fires when the React application is starting to be rendered on the server.
|
|
1687
|
+
*/
|
|
1688
1688
|
"react:server:render:begin": {
|
|
1689
1689
|
request?: ServerRequest;
|
|
1690
1690
|
state: ReactRouterState;
|
|
1691
1691
|
};
|
|
1692
1692
|
/**
|
|
1693
|
-
|
|
1694
|
-
|
|
1693
|
+
* Fires when the React application has been rendered on the server.
|
|
1694
|
+
*/
|
|
1695
1695
|
"react:server:render:end": {
|
|
1696
1696
|
request?: ServerRequest;
|
|
1697
1697
|
state: ReactRouterState;
|
|
1698
1698
|
html: string;
|
|
1699
1699
|
};
|
|
1700
1700
|
/**
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1701
|
+
* Fires when the React application is being rendered on the browser.
|
|
1702
|
+
*
|
|
1703
|
+
* Note: this one is not really necessary, it's a hack because we need to isolate renderer from server code in order
|
|
1704
|
+
* to avoid including react-dom/client in server bundles.
|
|
1705
|
+
*/
|
|
1706
1706
|
"react:browser:render": {
|
|
1707
1707
|
root: HTMLElement;
|
|
1708
1708
|
element: ReactNode;
|
|
@@ -1710,29 +1710,29 @@ declare module "alepha" {
|
|
|
1710
1710
|
hydration?: ReactHydrationState;
|
|
1711
1711
|
};
|
|
1712
1712
|
/**
|
|
1713
|
-
|
|
1714
|
-
|
|
1713
|
+
* Fires when a route transition is starting.
|
|
1714
|
+
*/
|
|
1715
1715
|
"react:transition:begin": {
|
|
1716
1716
|
previous: ReactRouterState;
|
|
1717
1717
|
state: ReactRouterState;
|
|
1718
1718
|
animation?: PageAnimation;
|
|
1719
1719
|
};
|
|
1720
1720
|
/**
|
|
1721
|
-
|
|
1722
|
-
|
|
1721
|
+
* Fires when a route transition has succeeded.
|
|
1722
|
+
*/
|
|
1723
1723
|
"react:transition:success": {
|
|
1724
1724
|
state: ReactRouterState;
|
|
1725
1725
|
};
|
|
1726
1726
|
/**
|
|
1727
|
-
|
|
1728
|
-
|
|
1727
|
+
* Fires when a route transition has failed.
|
|
1728
|
+
*/
|
|
1729
1729
|
"react:transition:error": {
|
|
1730
1730
|
state: ReactRouterState;
|
|
1731
1731
|
error: Error;
|
|
1732
1732
|
};
|
|
1733
1733
|
/**
|
|
1734
|
-
|
|
1735
|
-
|
|
1734
|
+
* Fires when a route transition has completed, regardless of success or failure.
|
|
1735
|
+
*/
|
|
1736
1736
|
"react:transition:end": {
|
|
1737
1737
|
state: ReactRouterState;
|
|
1738
1738
|
};
|