Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export function createComponentRendererComponent(params: {
} else {
const ownElementPath = EP.appendNewElementPath(instancePath, getUtopiaID(element))

return renderCoreElement(
const renderedCoreElement = renderCoreElement(
element,
ownElementPath,
mutableContext.rootScope,
Expand All @@ -188,6 +188,12 @@ export function createComponentRendererComponent(params: {
code,
highlightBounds,
)

if (typeof renderedCoreElement === 'string' || typeof renderedCoreElement === 'number') {
return <>{renderedCoreElement}</>
} else {
return renderedCoreElement
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ export function createLookupRender(
imports: Imports,
code: string,
highlightBounds: HighlightBoundsForUids | null,
): (element: JSXElement, scope: MapLike<any>) => React.ReactElement {
): (element: JSXElement, scope: MapLike<any>) => React.ReactChild {
let index = 0

return (element: JSXElement, scope: MapLike<any>): React.ReactElement => {
return (element: JSXElement, scope: MapLike<any>): React.ReactChild => {
index++
const innerUID = getUtopiaID(element)
const generatedUID = createIndexedUid(innerUID, index)
Expand Down Expand Up @@ -149,7 +149,7 @@ export function renderCoreElement(
imports: Imports,
code: string,
highlightBounds: HighlightBoundsForUids | null,
): React.ReactElement {
): React.ReactChild {
if (codeError != null) {
throw codeError
}
Expand Down Expand Up @@ -213,7 +213,7 @@ export function renderCoreElement(
return runJSXArbitraryBlock(requireResult, element, blockScope)
}
case 'JSX_FRAGMENT': {
let renderedChildren: Array<React.ReactElement> = []
let renderedChildren: Array<React.ReactChild> = []
fastForEach(element.children, (child) => {
const childPath = EP.appendToPath(EP.parentPath(elementPath), getUtopiaID(child))
const renderResult = renderCoreElement(
Expand Down Expand Up @@ -242,14 +242,7 @@ export function renderCoreElement(
return <>{renderedChildren}</>
}
case 'JSX_TEXT_BLOCK': {
// JSXTextBlock is the final remaining case.
return renderComponentUsingJsxFactoryFunction(
inScope,
jsxFactoryFunctionName,
React.Fragment,
{ key: elementPath == null ? uid : EP.toString(elementPath) },
element.text,
)
return element.text
}
default:
const _exhaustiveCheck: never = element
Expand Down Expand Up @@ -287,9 +280,7 @@ function renderJSXElement(
}
elementProps = streamlineInFileBlobs(elementProps, fileBlobs)

const createChildrenElement = (
child: JSXElementChild,
): React.ReactElement | Array<React.ReactElement> => {
const createChildrenElement = (child: JSXElementChild): React.ReactChild => {
const childPath = EP.appendToPath(elementPath, getUtopiaID(child))
return renderCoreElement(
child,
Expand Down Expand Up @@ -409,8 +400,8 @@ function hideElement(props: any): any {
export function utopiaCanvasJSXLookup(
elementsWithin: ElementsWithin,
executionScope: MapLike<any>,
render: (element: JSXElement, inScope: MapLike<any>) => React.ReactElement,
): (uid: string, inScope: MapLike<any>) => React.ReactElement | null {
render: (element: JSXElement, inScope: MapLike<any>) => React.ReactChild,
): (uid: string, inScope: MapLike<any>) => React.ReactChild | null {
return (uid, inScope) => {
const element = elementsWithin[uid]
if (element == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function buildSpyWrappedElement(
elementPath: ElementPath,
metadataContext: UiJsxCanvasContextData,
childrenElementPaths: Array<ElementPath>,
childrenElements: Array<React.ReactNode>,
childrenElements: Array<React.ReactChild>,
Element: any,
inScope: MapLike<any>,
jsxFactoryFunctionName: string | null,
Expand Down