FIX: additionalOpts update and change to function (PR #12546)

I made this PR a few days back. I encountered an issue there. The additionalOpts object is added to the options inside a conditional which isn’t desired. This resolves the issue.

GitHub

The title of this pull request changed from “FIX: additionalOpts should be added outside conditional” to "FIX: additionalOpts update and change to function

@eviltrout I’ve added another change. The additionalOpts need to update on each call and hence, it better be a function. Hope that’s acceptable.