-
Notifications
You must be signed in to change notification settings - Fork 1
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
properly remove script tags #9
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Double check that the component is SSR'd first. Can we add tests for dynamically added components?
@@ -35,7 +35,7 @@ const CustomElementMixin = (superclass) => class extends superclass { | |||
// Removes script tags as they are already appended to the body by SSR | |||
// TODO: If only added dynamically in the browser we need to insert the script tag after running the script transform on it. As well as handle deduplication. | |||
el.querySelectorAll('script') | |||
.forEach((tag) => { el.content.removeChild(tag) }) | |||
.forEach((tag) => { el.removeChild(tag) }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to guard this code with a check to see if the component is SSR'd or not. If they component is created dynamically this could remove a script tag the component needs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could be wrong, but I think the fact that it is running inside the custom element mixin render function itself means that the code to define the custom element has already run. I think that we might need to add a check so that if you want to add the script tag for some other reason it does not get removed. Like in the case of analytics etc. But then it needs to be deduplicated etc. so for now I think it is safest to remove it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to add some tests to illustrate what I was talking about but there is still a failure as the enhanced
attribute is not reset when modified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think my suggestion needs to be implemented in this PR so I'm going to approve this PR>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The most recent update of this mixin should not not tamper with the template anymore.
There is a todo in the code about injecting and deduplicating any script tags present in the template.
No description provided.