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

feat: add support for setting an id to the dynamically created script… #367

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

escobar-felipe
Copy link

… element in DeferScript component

This PR enhances the DeferScript component by allowing developers to assign an id to the dynamically created <script> element. This improvement provides better identification and traceability of injected scripts in the DOM, making debugging and management easier.

Changes:

Extracted the id prop and applied it to the <script> element when provided.
Updated PropTypes:
Made src a required prop.
Validated id as an optional string.
Added logic in componentDidMount to set the id attribute on the <script> element.

Why is this needed?

The ability to assign an id to the <script> element is crucial for:

Avoiding duplicate script injection.
Simplifying script tracking and debugging.
Allowing DOM manipulation or monitoring of specific scripts.

Testing:

Verified that the id attribute is correctly applied when passed as a prop.
Ensured backward compatibility by keeping id optional.

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.

1 participant