Skip to content

[5.0.3] Provider with multiple children makes renderToString return <undefined/> #95

@johannesodland

Description

@johannesodland

If a provider has multiple children then the result of a render is an array of VNodes. RenderToString tries to fetch the nodeName of this array on line 180: s = `<${nodeName}${s}>`; . The result is the string <undefined>.

This breaks server side rendering of valid Preact applications.

const TestContext = createContext();
function TestComponent() {
   
   return <TestContext.Provider>
      <div>1</div>
      <div>2</div>
   </TestContext.Provider>
}

Preact 10.0.0-beta.2 handles this case by coercing the array to a fragment:

	if (Array.isArray(possibleVNode)) {
		return createElement(Fragment, null, possibleVNode);
	}

Maybe preact-render-to-string should coerce the render result to vnodes too?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions