feat: add support for setting an id to the dynamically created script… #367
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
… 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.