|
12 | 12 | * body/children for backward compatibility. |
13 | 13 | */ |
14 | 14 |
|
15 | | -import React from 'react'; |
| 15 | +import React, { useMemo } from 'react'; |
16 | 16 | import type { PageSchema, PageRegion, SchemaNode } from '@object-ui/types'; |
17 | 17 | import { SchemaRenderer, PageVariablesProvider } from '@object-ui/react'; |
18 | 18 | import { ComponentRegistry } from '@object-ui/core'; |
@@ -357,29 +357,25 @@ export const PageRenderer: React.FC<{ |
357 | 357 | } = props; |
358 | 358 |
|
359 | 359 | // Select the layout variant based on template or page type |
360 | | - const TemplateLayout = resolveTemplate(schema); |
361 | | - let LayoutVariant: React.FC<{ schema: PageSchema }>; |
362 | | - |
363 | | - if (TemplateLayout) { |
364 | | - // Template takes priority over page type |
365 | | - LayoutVariant = TemplateLayout; |
366 | | - } else { |
| 360 | + const layoutElement = useMemo(() => { |
| 361 | + const TemplateLayout = resolveTemplate(schema); |
| 362 | + if (TemplateLayout) { |
| 363 | + // Template takes priority over page type |
| 364 | + // eslint-disable-next-line react-hooks/static-components -- TemplateLayout is resolved from a stable template registry |
| 365 | + return <TemplateLayout schema={schema} />; |
| 366 | + } |
367 | 367 | switch (pageType) { |
368 | 368 | case 'home': |
369 | | - LayoutVariant = HomePageLayout; |
370 | | - break; |
| 369 | + return <HomePageLayout schema={schema} />; |
371 | 370 | case 'app': |
372 | | - LayoutVariant = AppPageLayout; |
373 | | - break; |
| 371 | + return <AppPageLayout schema={schema} />; |
374 | 372 | case 'utility': |
375 | | - LayoutVariant = UtilityPageLayout; |
376 | | - break; |
| 373 | + return <UtilityPageLayout schema={schema} />; |
377 | 374 | case 'record': |
378 | 375 | default: |
379 | | - LayoutVariant = RecordPageLayout; |
380 | | - break; |
| 376 | + return <RecordPageLayout schema={schema} />; |
381 | 377 | } |
382 | | - } |
| 378 | + }, [schema, pageType]); |
383 | 379 |
|
384 | 380 | const pageContent = ( |
385 | 381 | <div |
@@ -409,7 +405,7 @@ export const PageRenderer: React.FC<{ |
409 | 405 | )} |
410 | 406 |
|
411 | 407 | {/* Page body — type-specific layout */} |
412 | | - <LayoutVariant schema={schema} /> |
| 408 | + {layoutElement} |
413 | 409 | </div> |
414 | 410 | </div> |
415 | 411 | ); |
|
0 commit comments