Skip to content

Commit

Permalink
fix: render empty root content if bodyContent.root is not set (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
ValeraS authored Aug 15, 2023
1 parent 16e6094 commit 1db127a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/render.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,10 @@ test('should allow `<html>` attributes override', () => {
expect(createRenderFunction()({title: 'Foobar'})).toMatch('<html >');
expect(createRenderFunction([dirPlugin()])({title: 'Foobar'})).toMatch('<html dir="ltr">');
});

test('should render root content', () => {
expect(createRenderFunction()({title: 'Foobar'})).toMatch(/<div id="root">\s*<\/div>/);
expect(createRenderFunction()({title: 'Foobar', bodyContent: {root: 'content'}})).toMatch(
/<div id="root">\s*content\s*<\/div>/,
);
});
2 changes: 1 addition & 1 deletion src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export function createRenderFunction<Plugins extends Plugin[]>(plugins?: Plugins
<body ${attrs({class: bodyContent.className.filter(Boolean).join(' ')})}>
${bodyContent.beforeRoot.join('\n')}
<div id="root">
${bodyContent.root}
${bodyContent.root ?? ''}
</div>
${bodyContent.afterRoot.join('\n')}
</body>
Expand Down

0 comments on commit 1db127a

Please sign in to comment.