@@ -631,18 +698,201 @@ export class Head extends React.Component<HeadProps> {
)
}
lethasAmphtmlRel=false
lethasCanonicalRel=false
// show warning and remove conflicting amp head tags
head=React.Children.map(head||[],(child)=>{
if(!child)returnchild
const{type,props}=child
if(process.env.NEXT_RUNTIME!=='edge'&&inAmpMode){
letbadProp:string=''
if(type==='meta'&&props.name==='viewport'){
badProp='name="viewport"'
}elseif(type==='link'&&props.rel==='canonical'){
hasCanonicalRel=true
}elseif(type==='script'){
// only block if
// 1. it has a src and isn't pointing to ampproject's CDN
// 2. it is using dangerouslySetInnerHTML without a type or
// a type of text/javascript
if(
(props.src&&props.src.indexOf('ampproject')<-1)||
(props.dangerouslySetInnerHTML&&
(!props.type||props.type==='text/javascript'))
){
badProp='<script'
Object.keys(props).forEach((prop)=>{
badProp+=` ${prop}="${props[prop]}"`
})
badProp+='/>'
}
}
if(badProp){
console.warn(
`Found conflicting amp tag "${child.type}" with conflicting prop ${badProp} in ${__NEXT_DATA__.page}. https://nextjs.org/docs/messages/conflicting-amp-tag`
)
returnnull
}
}else{
// non-amp mode
if(type==='link'&&props.rel==='amphtml'){
hasAmphtmlRel=true
}
}
returnchild
// @types/react bug. Returned value from .map will not be `null` if you pass in `[null]`