Revert "Fix children not rendering when render() called from different module"
This reverts commit 9b8d789da0.
This commit is contained in:
parent
9b8d789da0
commit
fe89360ac5
|
|
@ -147,10 +147,8 @@ function makeStyle(def: TagDef) {
|
|||
return style
|
||||
}
|
||||
|
||||
const ROOT_PROPS_KEY = '_forgeRootProps'
|
||||
|
||||
// turns a TagDef into a JSX component
|
||||
function makeComponent(baseName: string, rootDef: TagDef, partName?: string) {
|
||||
function makeComponent(baseName: string, rootDef: TagDef, rootProps: Record<string, any>, partName?: string) {
|
||||
const def = partName ? rootDef.parts?.[partName]! : rootDef
|
||||
const base = def.base ?? 'div'
|
||||
|
||||
|
|
@ -169,7 +167,7 @@ function makeComponent(baseName: string, rootDef: TagDef, partName?: string) {
|
|||
}
|
||||
}
|
||||
|
||||
return ({ [ROOT_PROPS_KEY]: rootProps = {}, children, ...props }: { [ROOT_PROPS_KEY]?: Record<string, any>, children: any, [key: string]: any }) => {
|
||||
return ({ children, ...props }: { children: any, [key: string]: any }) => {
|
||||
const classNames = [makeClassName(baseName, partName)]
|
||||
|
||||
const allProps = { ...rootProps, ...props }
|
||||
|
|
@ -288,28 +286,14 @@ export function define(nameOrDef: string | TagDef, defIfNamed?: TagDef) {
|
|||
if (styles[name]) throw `${name} is already defined! Must use unique names.`
|
||||
registerStyles(name, def)
|
||||
|
||||
// ensure component function identity doesn't change between renders
|
||||
const components: Record<string, (props: any) => any> = {}
|
||||
|
||||
for (const [partName] of Object.entries(def.parts ?? {}))
|
||||
components[partName] = makeComponent(name, def, partName)
|
||||
|
||||
const RootComponent = makeComponent(name, def)
|
||||
|
||||
return (props: Record<string, any>) => {
|
||||
if (def.render) {
|
||||
// For custom render, create parts object that injects _forgeRootProps
|
||||
const parts: Record<string, (partProps: any) => any> = {}
|
||||
const parts: Record<string, Function> = {}
|
||||
|
||||
for (const [partName, Comp] of Object.entries(components))
|
||||
parts[partName] = (partProps: any) => <Comp {...{ [ROOT_PROPS_KEY]: props }} {...partProps} />
|
||||
for (const [part] of Object.entries(def.parts ?? {}))
|
||||
parts[part] = makeComponent(name, def, props, part)
|
||||
|
||||
parts.Root = (partProps: any) => <RootComponent {...{ [ROOT_PROPS_KEY]: props }} {...partProps} />
|
||||
return def.render({ props, parts })
|
||||
}
|
||||
|
||||
// Default render
|
||||
return <RootComponent {...{ [ROOT_PROPS_KEY]: props }} {...props}>{props.children}</RootComponent>
|
||||
parts.Root = makeComponent(name, def, props)
|
||||
return def.render?.({ props, parts }) ?? <parts.Root {...props}>{props.children}</parts.Root>
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user