Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(fix): Missing default values for nested components #945

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 20 additions & 14 deletions packages/teleport-plugin-html-base-component/src/node-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -615,11 +615,12 @@ const generateComponentContent = async (

const generateDynamicNode: NodeToHTML<UIDLDynamicReference, Promise<HastNode | HastText>> = async (
node,
/* tslint:disable variable-name */
_compName,
compName,
nodesLookup,
propDefinitions,
stateDefinitions
stateDefinitions,
subComponentOptions,
structure
): Promise<HastNode | HastText> => {
if (node.content.referenceType === 'locale') {
const localeTag = HASTBuilders.createHTMLNode('span')
Expand Down Expand Up @@ -650,11 +651,23 @@ const generateDynamicNode: NodeToHTML<UIDLDynamicReference, Promise<HastNode | H
}
}

if (usedReferenceValue.type === 'element' && usedReferenceValue.defaultValue) {
if (usedReferenceValue.type === 'element') {
const elementNode = usedReferenceValue.defaultValue as UIDLElementNode

if (elementNode.content.key in nodesLookup) {
return nodesLookup[elementNode.content.key]
if (elementNode) {
if (elementNode.content.key in nodesLookup) {
return nodesLookup[elementNode.content.key]
} else {
const elementTag = await generateHtmlSyntax(
elementNode,
compName,
nodesLookup,
propDefinitions,
stateDefinitions,
subComponentOptions,
structure
)
return elementTag
}
}

const spanTagWrapper = HASTBuilders.createHTMLNode('span')
Expand All @@ -663,13 +676,6 @@ const generateDynamicNode: NodeToHTML<UIDLDynamicReference, Promise<HastNode | H
return spanTagWrapper
}

if (usedReferenceValue.type === 'element' && usedReferenceValue.defaultValue === undefined) {
const spanTagWrapper = HASTBuilders.createHTMLNode('span')
const commentNode = HASTBuilders.createComment(`Content for slot ${node.content.id}`)
HASTUtils.addChildNode(spanTagWrapper, commentNode)
return spanTagWrapper
}

const spanTag = HASTBuilders.createHTMLNode('span')
HASTUtils.addTextNode(spanTag, String(usedReferenceValue.defaultValue))
return spanTag
Expand Down
Loading