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

Fixed Handlebars/EJS template caching #888

Merged
merged 2 commits into from
Jan 26, 2023

Conversation

Bioruebe
Copy link
Contributor

When organizing templates in subfolders, files with the same name are not rendered correctly. This is because Handlebars and EJS adapters precompile the templates and put them into a lookup object. However, as only the template name is used as the key, files from different subfolders cannot be distinguished. E.g.:

/templates
  /en
    myTemplate.hbs
  /es
    myTemplate.hbs

Using en/myTemplate renders the correct English file, any follow up calls use the cached English file as well, even if we pass es/myTemplate. As a workaround we can use a prefix to make file names unique, as mentioned in #684, but imho it's better to have mailer support this natively.

This pull request changes the keys of the lookup objects to the full relative paths, e.g. en/myTemplate instead of only myTemplate to fix the issue.

When using a hierarchical structure for the template folder, in which some files have the same name, only the template that gets rendered first will be used. Any subsequent calls will use the first template instead of the one actually passed, due to the precompiling step using only the file name as the key to the lookup object. This commit changes the key to the full relative path to fix this issue.
When using a hierarchical structure for the template folder, in which some files have the same name, only the template that gets rendered first will be used. Any subsequent calls will use the first template instead of the one actually passed, due to the precompiling step using only the file name as the key to the lookup object. This commit changes the key to the full relative path to fix this issue.
Copy link
Member

@juandav juandav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@juandav juandav merged commit f37977c into nest-modules:master Jan 26, 2023
@VagnerDuka
Copy link

Hi,
Do you have plans to publish a new version?

@spaquis
Copy link

spaquis commented Jun 30, 2023

Hi,
Can you push a new tag with this ?
Thanks in advance

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 this pull request may close these issues.

4 participants