-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
express-hbs 2.0.2 causes infinite loops and crashes Ghost #10643
Comments
UpdateThis issue can now be traced back to here: https://github.com/barc/express-hbs/blob/v2.1.2/lib/hbs.js#L364-L366 In some circumstances, the value of In this case, the promise will be added to a "resolverCache" which is not shared between helpers, so when Fix (possible)This can be fixed by replacing the highlighted lines from above with: var resolverCache = _.get(context, 'data.root.resolverCache') ||
_.get(options, 'data.root.resolverCache') ||
this.resolverCache; This changes forces StatusI have still not managed to replicate this outside of Ghost, but it seems to be occurring when a block helper is used like Handlebars documentation states that a helper will always be called with a I'm going to continue to try to produce a breaking test for this, though if we can't, I would suggest moving forward with the patch detailed above. |
closes TryGhost#10643 The async resolver in express-hbs relies on storing the state of the promises on the `this` value inside of a helper, which is always set to the `context`. This patch updates our helpers which render templates, to use `this` as the context when rendering their templates.
closes #10643 The async resolver in express-hbs relies on storing the state of the promises on the `this` value inside of a helper, which is always set to the `context`. This patch updates our helpers which render templates, to use `this` as the context when rendering their templates.
#10642 reverts the update to express 2.0.2 to avoid this bug.
Issue summary
When using the
{{#get}}
helper inside of a helper's template file, Ghost seems to end up in an infinite loop and crashes.Technical details
In an effort to narrow the cause of the problem the following scenarios have been tested (✅=working, ❌=infinite loop):
{{#get}}
inside a regular partial{{#get}}
inside the originalnavigation.hbs
used by{{navigation}}
{{#get}}
inside of a theme'spartials/navigation.hbs
override{{#get}}
inside thepagination.hbs
file or a theme overrideOur template-driven helpers all use
templates.execute()
which compiles a hbs template string if necessary then calls the resulting function. These are non-async helpers, whereas{{get}}
is an async helper (returns promise).I've generated a flamegraph which highlights the calls within
express-hbs
here and here that appear to be looping.The text was updated successfully, but these errors were encountered: