Skip to content

Commit

Permalink
fix recursive component rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
bjrmatos committed Mar 22, 2024
1 parent 8c1d732 commit 20f0140
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
32 changes: 32 additions & 0 deletions packages/jsreport-components/test/test.js
Expand Up @@ -85,6 +85,38 @@ describe('components', function () {
res.content.toString().should.be.eql('c1c2myHelper')
})

it('should evaluate recursive component using handlebars', async () => {
await reporter.documentStore.collection('components').insert({
name: 'c1',
content: '{{#each children}}{{component "c1"}}{{/each}}{{name}}',
engine: 'handlebars'
})

const res = await reporter.render({
template: {
content: '{{component "c1"}}',
recipe: 'html',
engine: 'handlebars'
},
data: {
children: [
{
children: [
{
name: 'john'
},
{
name: 'peter'
}
]
}
]
}
})

res.content.toString().should.be.eql('johnpeter')
})

it('should propagate logs from nested components', async () => {
await reporter.documentStore.collection('components').insert({
name: 'c1',
Expand Down
2 changes: 1 addition & 1 deletion packages/jsreport-core/lib/worker/render/executeEngine.js
Expand Up @@ -253,7 +253,7 @@ module.exports = (reporter) => {
}
contentResult = contentResult.replace(/asyncUnresolvedHelperResult/g, 'asyncHelperResult')

await executionFinishListenersMap.get(context.__executionId).fire()
await executionFinishListenersMap.get(executionId).fire()

return {
// handlebars escapes single brackets before execution to prevent errors on {#asset}
Expand Down

0 comments on commit 20f0140

Please sign in to comment.