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

Rename next/script interface Props to ScriptProps #26990

Merged
merged 3 commits into from
Jul 7, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions packages/next/client/script.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@ import { requestIdleCallback } from './request-idle-callback'
const ScriptCache = new Map()
const LoadCache = new Set()

export interface Props extends ScriptHTMLAttributes<HTMLScriptElement> {
export interface ScriptProps extends ScriptHTMLAttributes<HTMLScriptElement> {
strategy?: 'afterInteractive' | 'lazyOnload' | 'beforeInteractive'
id?: string
onLoad?: () => void
onError?: () => void
children?: React.ReactNode
}

/**
* @deprecated Use `ScriptProps` instead.
*/
export type Props = ScriptProps

const ignoreProps = [
'onLoad',
'dangerouslySetInnerHTML',
Expand All @@ -23,7 +28,7 @@ const ignoreProps = [
'strategy',
]

const loadScript = (props: Props): void => {
const loadScript = (props: ScriptProps): void => {
const {
src,
id,
Expand Down Expand Up @@ -90,7 +95,7 @@ const loadScript = (props: Props): void => {
document.body.appendChild(el)
}

function handleClientScriptLoad(props: Props) {
function handleClientScriptLoad(props: ScriptProps) {
const { strategy = 'afterInteractive' } = props
if (strategy === 'afterInteractive') {
loadScript(props)
Expand All @@ -101,7 +106,7 @@ function handleClientScriptLoad(props: Props) {
}
}

function loadLazyScript(props: Props) {
function loadLazyScript(props: ScriptProps) {
if (document.readyState === 'complete') {
requestIdleCallback(() => loadScript(props))
} else {
Expand All @@ -111,11 +116,11 @@ function loadLazyScript(props: Props) {
}
}

export function initScriptLoader(scriptLoaderItems: Props[]) {
export function initScriptLoader(scriptLoaderItems: ScriptProps[]) {
scriptLoaderItems.forEach(handleClientScriptLoad)
}

function Script(props: Props): JSX.Element | null {
function Script(props: ScriptProps): JSX.Element | null {
const {
src = '',
onLoad = () => {},
Expand Down
6 changes: 3 additions & 3 deletions packages/next/pages/_document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
import { BuildManifest, getPageFiles } from '../server/get-page-files'
import { cleanAmpPath } from '../server/utils'
import { htmlEscapeJsonString } from '../server/htmlescape'
import Script, { Props as ScriptLoaderProps } from '../client/script'
import Script, { ScriptProps } from '../client/script'

export { DocumentContext, DocumentInitialProps, DocumentProps }

Expand Down Expand Up @@ -76,7 +76,7 @@ function getPreNextScripts(context: DocumentProps, props: OriginProps) {
const { scriptLoader, disableOptimizedLoading } = context

return (scriptLoader.beforeInteractive || []).map(
(file: ScriptLoaderProps, index: number) => {
(file: ScriptProps, index: number) => {
const { strategy, ...scriptProps } = file
return (
<script
Expand Down Expand Up @@ -408,7 +408,7 @@ export class Head extends Component<

handleDocumentScriptLoaderItems(children: React.ReactNode): ReactNode[] {
const { scriptLoader } = this.context
const scriptLoaderItems: ScriptLoaderProps[] = []
const scriptLoaderItems: ScriptProps[] = []
const filteredChildren: ReactNode[] = []

React.Children.forEach(children, (child: any) => {
Expand Down