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

Meta errors when rendering multiple times concurrently #91

Open
BenMansley opened this issue Mar 18, 2019 · 7 comments
Open

Meta errors when rendering multiple times concurrently #91

BenMansley opened this issue Mar 18, 2019 · 7 comments

Comments

@BenMansley
Copy link

Version: 1.1.3

Our company have recently converted all our emails to heml, and have been loving its simplicity so far. All of the emails we've sent so far have been transactional, where we've only sent them one at a time, and it's worked without a hitch. We're now implementing a monthly report for our users which will be sent out in bulk, and we're seeing errors in development.

The error trace is as follows:

TypeError: null is not iterable!
    at module.exports.require.getIterator (/Users/admin/Documents/backend/node_modules/core-js/library/modules/core.get-iterator.js:5:42)
    at Object.flush (/Users/admin/Documents/backend/node_modules/@heml/elements/build/Meta.js:60:54)
    at _callee$ (/Users/admin/Documents/backend/node_modules/@heml/render/build/index.js:343:73)
    at tryCatch (/Users/admin/Documents/backend/node_modules/regenerator-runtime/runtime.js:62:40)
    at Generator.invoke [as _invoke] (/Users/admin/Documents/backend/node_modules/regenerator-runtime/runtime.js:296:22)
    at Generator.prototype.(anonymous function) [as next] (/Users/admin/Documents/backend/node_modules/regenerator-runtime/runtime.js:114:21)
    at step (/Users/admin/Documents/backend/node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30)
    at /Users/admin/Documents/backend/node_modules/babel-runtime/helpers/asyncToGenerator.js:28:13

This seems to be caused by Meta - the metaMap Map is being flushed on the first render (this line), then the null Map is causing errors in subsequent renders.

Is there a preferred method to handle rendering multiple emails concurrently, or is this a bug? Happy to provide any more information if required - otherwise I suppose the quickest fix for us would be to build the emails in series.

Thanks,
Ben Mansley

@BenMansley BenMansley changed the title Meta errors when calling heml multiple times Meta errors when rendering multiple times concurrently Mar 18, 2019
@GemN
Copy link

GemN commented Jul 8, 2019

Hello,
Got exactly the same problems when rendering emails to send to different customers in AWS lambda

@robmcfeely
Copy link

@BenMansley @GemN or anyone find a solution to this? Same problem. It pretty much renders this project useless for service type activity :(

@Devessier
Copy link

I'm getting the same error.
Has anybody found a solution or a workaround 😄 ? @BenMansley @GemN @robmcfeely

@robmcfeely
Copy link

robmcfeely commented Feb 10, 2020 via email

@Devessier
Copy link

@robmcfeely Okay, thank your for your reply ! 👍

@GemN
Copy link

GemN commented Feb 11, 2020

I found a workaround.
I actually build with a script all my folder heml, into a folder html. Push both folders and in the code I directly load from the html folder (and for variables i use Mustache)

Script to build:

#!/bin/bash
type heml >/dev/null 2>&1 || { echo >&2 "Require heml. Please install (yarn global add heml)."; exit 1; }

for entry in "heml"/*
do
  if [ -f "$entry" ];then
    echo "-- Building $entry to html"
    filename=${entry##*/}
    heml build $entry --output html/${filename%.*}.html
  fi
done

Load html email:

const htmlEmail = fs.readFileSync(`${__dirname}/../emails/templates/html/myemail.html`, {
  encoding: 'utf-8',
});

Build the emails with dynamic variables:

const htmlEmailWithValues = Mustache.render(htmlEmail, emailData);
const form = new FormData();
form.append('from', 'App <[email protected]>');
form.append('to', `${firstname} <${email}>`);
form.append('subject', subject);
form.append('html', htmlEmailWithValues);

@Devessier
Copy link

@GemN Great workaround !

I think I would have used your solution if I wouldn't must dynamically generate content using loops or conditions.
I created a small class that spawns 4 Node.js thread workers, each of them executing the heml function while waiting for the previous execution to be completed in order to prevent race conditions we encountered.
Like that I don't need to rely on HEML CLI.

The Gist containing the code : https://gist.github.com/Devessier/f17c3bf4e7f9a799059d1fec110ba841

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

No branches or pull requests

4 participants