Created
August 25, 2020 21:59
-
-
Save prateekbh/10092e7a4b5b6d7bae354ddcc3112bcf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class DeferScripts extends NextScript { | |
| makeScriptsDefer(el) { | |
| return React.Children.map(el, child => { | |
| if (!child) { | |
| return child; | |
| } | |
| if (child.props.children) { | |
| child.props.children = this.makeScriptsDefer(child.props.children) | |
| } else { | |
| const newProps = {...child.props || {}}; | |
| newProps.async = false; | |
| newProps.defer = true; | |
| return React.cloneElement(child, newProps); | |
| } | |
| return child; | |
| }); | |
| } | |
| render() { | |
| const nextScripts = super.render(); | |
| return this.makeScriptsDefer(nextScripts); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment