I'm working on a public app and adding a ScriptTag using scriptTagCreate.
Should scriptTagCreate return an error if I try to add the exact same ScriptTag, with the same URL, multiple times?
At the moment, it appears that it is allowing the app to add multiple duplicates of the exact same ScriptTag, which in turn creates duplicate JS scripts on the page.
Should I be manually checking first to see is that ScriptTag already exists?
Do you use the APP CLI and add your script in the afterAuth function?
It will not give an error and add that ScriptTag several times...
I had the same issue and end up to check up for the ScriptTag existence and add it based on that.
@Mircea_Piturca - Thanks. Yes (I think that's what we're doing).
In the Node server, within afterAuth, we're then adding the ScriptTag using the GraphQL API to push a scriptTagCreate mutation.
So if the Shopify API itself doesn’t catch duplicate ScriptTags as an error, checking if the ScriptTag already exists first makes sense. That sounds good.
I just want to check that there isn’t a better point in the app lifecycle to be implementing scriptTagCreate.
The APP CLI is using cookies for authentication. When those cookies are deleted, your all will run the afterAuth again. This causes the ScriptTag mutation to be called again.
Hopefully, a new APP CLI version that will use JWT tokens for auth will solve this issue.
There are probably more elegant ways of handling this but for now, I am checking the script presence before running the mutation.
Hope this helps
Are you doing that check through GraphQL query?
With the REST API, there's this method to confirm if a ScriptTag already exists:
But I can't figure out the equivalent GraphQL query required to check for the presence of a specific ScriptTag by src URL.