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

env.render() invokes the callback twice #1029

Closed
Spown opened this issue Sep 23, 2017 · 1 comment · Fixed by #1049
Closed

env.render() invokes the callback twice #1029

Spown opened this issue Sep 23, 2017 · 1 comment · Fixed by #1049

Comments

@Spown
Copy link

Spown commented Sep 23, 2017

Node: 6, 7
Nunjucks: 3.0.1
OS: Win 10x64

Under specific circumstances, when a templating error occurs the callback of the .render() method runs twice: one for the error and one more time returning an incomplete output. In the test case provided I took my project and reduced it to a minimum condition for this to happen. Just run it and the output should show something like this

sending for webpage content
render #1 
 error is: 
 Template render error: (d:\Projects\nunj_double_rainder\tmpl\views\page_view.html)
  Template render error: (d:\Projects\nunj_double_rainder\tmpl\mixins\_header.html)
  Template render error: (d:\Projects\nunj_double_rainder\tmpl\mixins\_register_auth.html)
  Error: Unable to call `map_elements["nonExistantMacro"]`, which is undefined or falsey 
 rendered content is: 
 undefined
render #2 
 error is: 
 null 
 rendered content is: 
 Layout
 |- [<- extends] Serial Layout:
    |- [<- includes] _Header:
      |- [<- includes] _register_auth:
    |- [<- extends] page_view
    |/_Header
 |/Serial Layout
/Layout
express app.send(): Error: Can't set headers after they are sent.
got webpage content length: <h1>U FAIL!</h1><div>Reason: Template render error: (d:\Projects\nunj_double_rainder\tmpl\views\page_view.html)
  Template render error: (d:\Projects\nunj_double_rainder\tmpl\mixins\_header.html)
  Template render error: (d:\Projects\nunj_double_rainder\tmpl\mixins\_register_auth.html)
  Error: Unable to call `map_elements["nonExistantMacro"]`, which is undefined or falsey</div>

Here the second callback run yelds a text, where it lacks |- [<- import] map_elements: after |- [<- includes] _register_auth: from
here

Further investigation has shown that if I unwrap this (if I remove the if check) - the whole construction starts to work as it should.

This error may be a very circumstantial, but it is also very serious, since render callback often contains the express's .send() method and it throws exception if you try to send the second time, potentially crashing the whole app, not just failing to render one page. If not caught that is...

I tried to traceback it but some parts seem to be async and there is just too much VM noise so I loose the track of the callback after going like 20 steps deep into .render()

devoidfury added a commit to devoidfury/nunjucks that referenced this issue Jan 8, 2018
devoidfury added a commit to devoidfury/nunjucks that referenced this issue Jan 8, 2018
fdintino added a commit that referenced this issue Jan 15, 2018
@devalexqt
Copy link

devalexqt commented Jan 25, 2019

Not fully fixed!
If include Same text <<__('hahaha(%s)',${sdsd})>> structure inside template when env.render callback will be fired twice. One with no err but partial html and second time with error message.
v3.1.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants