Skip to content

Commit 0d9bfde

Browse files
committed
Ignore AMP errors caused by React (for now)
1 parent e50e6aa commit 0d9bfde

File tree

2 files changed

+72
-2
lines changed

2 files changed

+72
-2
lines changed

packages/next/src/export/routes/pages.ts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,42 @@ export async function exportPagesPage(
138138
) => {
139139
const validator = await getAmpValidatorInstance(validatorPath)
140140
const result = validator.validateString(rawAmpHtml)
141-
const errors = result.errors.filter((e) => e.severity === 'ERROR')
141+
const errors = result.errors.filter((error) => {
142+
if (error.severity === 'ERROR') {
143+
// Unclear yet if these actually prevent the page from being indexed by the AMP cache.
144+
// These are coming from React so all we can do is ignore them for now.
145+
146+
// <link rel="expect" blocking="render" />
147+
// https://github.com/ampproject/amphtml/issues/40279
148+
if (
149+
error.code === 'DISALLOWED_ATTR' &&
150+
error.params[0] === 'blocking' &&
151+
error.params[1] === 'link'
152+
) {
153+
return false
154+
}
155+
// <template> without type
156+
// https://github.com/ampproject/amphtml/issues/40280
157+
if (
158+
error.code === 'MANDATORY_ATTR_MISSING' &&
159+
error.params[0] === 'type' &&
160+
error.params[1] === 'template'
161+
) {
162+
return false
163+
}
164+
// <template> without type
165+
// https://github.com/ampproject/amphtml/issues/40280
166+
if (
167+
error.code === 'MISSING_REQUIRED_EXTENSION' &&
168+
error.params[0] === 'template' &&
169+
error.params[1] === 'amp-mustache'
170+
) {
171+
return false
172+
}
173+
return true
174+
}
175+
return false
176+
})
142177
const warnings = result.errors.filter((e) => e.severity !== 'ERROR')
143178

144179
if (warnings.length || errors.length) {

packages/next/src/server/dev/next-dev-server.ts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,42 @@ export default class DevServer extends Server {
188188
ampValidation(
189189
pathname,
190190
result.errors
191-
.filter((e) => e.severity === 'ERROR')
191+
.filter((error) => {
192+
if (error.severity === 'ERROR') {
193+
// Unclear yet if these actually prevent the page from being indexed by the AMP cache.
194+
// These are coming from React so all we can do is ignore them for now.
195+
196+
// <link rel="expect" blocking="render" />
197+
// https://github.com/ampproject/amphtml/issues/40279
198+
if (
199+
error.code === 'DISALLOWED_ATTR' &&
200+
error.params[0] === 'blocking' &&
201+
error.params[1] === 'link'
202+
) {
203+
return false
204+
}
205+
// <template> without type
206+
// https://github.com/ampproject/amphtml/issues/40280
207+
if (
208+
error.code === 'MANDATORY_ATTR_MISSING' &&
209+
error.params[0] === 'type' &&
210+
error.params[1] === 'template'
211+
) {
212+
return false
213+
}
214+
// <template> without type
215+
// https://github.com/ampproject/amphtml/issues/40280
216+
if (
217+
error.code === 'MISSING_REQUIRED_EXTENSION' &&
218+
error.params[0] === 'template' &&
219+
error.params[1] === 'amp-mustache'
220+
) {
221+
return false
222+
}
223+
return true
224+
}
225+
return false
226+
})
192227
.filter((e) => this._filterAmpDevelopmentScript(html, e)),
193228
result.errors.filter((e) => e.severity !== 'ERROR')
194229
)

0 commit comments

Comments
 (0)