-
Notifications
You must be signed in to change notification settings - Fork 438
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: gtm scripts not working with loadScriptsOnMainThread by id #399
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
This looks great, but should the test be setting |
@adamdbradley actually the test is setting text via script.text. The set by innerHTML is just setting the response result to testInlineTextScript which is only used by the test suite to assert the result, which is already outside of partytown at that point. |
Sorry I must be misunderstanding then. How is this testing that setting |
ya no problem, note where it says <code id="testInlineTextScript"></code>
<script type="text/javascript">const globalVariable2 = 12;</script>
<script type="text/partytown">
(function () {
// This script is now running from partytown
// Create a new script to run outside of partytown
const script = document.createElement('script');
script.type = "text/javascript";
script.id = "inline-text-test-script";
// Set the body of the script via script.text
// This is the main logic of the function, which previously did not work with partytown
script.text = `
(function () {`+
// This script is only for the test suite, and is run outside of partytown therefore it can be ignored
// The test suite is just going to watch and see if testInlineTextScript is set to 12
// which would not happen if this was running in the webworker still as globalVariable2 is only set in the main thread
`const testEl = document.getElementById('testInlineTextScript');
testEl.className = 'testInlineTextScript';
testEl.innerHTML = globalVariable2;
})();
`;
document.body.appendChild(script);
})();
</script> |
@adamdbradley Hey, I just wanted to follow up to see if you need any more information/if the PR is good to go |
@adamdbradley I have the same bug as well, and this PR fixes it. You can repro it by creating Custom HTML tag in GTM, add there something like |
For what it's worth, I suggested fix for the the same issue some time ago here: #234, I believe the MR was mistakenly closed. Now I don't quite remember why, but my proposed fix had some additional logic in the |
This PR is old, so I'm closing this for now. |
GTM uses the
text
field when settings up an element.Ex. from the gtm script
Added field watch for
text
to the element patch code.Test code is added is well.