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

fix: fix find of undefined error #155

Closed
wants to merge 1 commit into from
Closed

Conversation

Botz
Copy link

@Botz Botz commented Jun 23, 2022

In some combinations(maybe with @nuxtsj/compositions-api?) app.head is a function instead of object which leads to an error
#141

@mazemax
Copy link

mazemax commented Sep 23, 2022

Getting same error on my side after upgrade to Nuxt 2.15.8

@mazemax
Copy link

mazemax commented Sep 23, 2022

@pi0 @SkyaTura @rchl @manniL Can you help fix the CI issue?

@SkyaTura
Copy link
Contributor

I don't have write permission, sorry :/

Comment on lines +35 to +44
const head = typeof ctx.app.head === 'function' ? ctx.app.head() : ctx.app.head;

const gtmScript = head.script.find(s => s.hid == '<%= options.scriptId %>')
gtmScript.innerHTML = `window['${_layer}']=${JSON.stringify(events)};${gtmScript.innerHTML}`

if (inits.length) {
gtmScript.innerHTML += `;${JSON.stringify(inits)}.forEach(function(i){window._gtm_inject(i)})`
}
<% if (options.noscript) { %>
const gtmIframe = ctx.app.head.noscript.find(s => s.hid == '<%= options.noscriptId %>')
const gtmIframe = head.noscript.find(s => s.hid == '<%= options.noscriptId %>')
Copy link
Member

@rchl rchl Sep 23, 2022

Choose a reason for hiding this comment

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

This is not a correct fix. The intention of the original code was to modify the innerHTML of the script added to head. When head is a function you can't modify the original script as your will (most likely) receive a new head object every time the function is called.

So this change will prevent the crash while at the same time make this part of the code not do anything useful.

@Botz Botz closed this May 23, 2023
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