未验证 提交 1c305ab3 编写于 作者: J JJ Kasper 提交者: GitHub

Add Amp bind error message (#6962)

上级 04df54a3
......@@ -27,8 +27,14 @@ export function createHook(fetcher: (...args: Args[]) => Promise<any>, options:
const dataManager: import('next-server/lib/data-manager').DataManager = useContext(DataManagerContext)
const key = `${options.key}${generateArgsKey(args)}`
const existing = dataManager.get(key)
if (existing && existing.status === 'resolved') {
return existing.result
if (existing) {
if (existing.status === 'resolved') {
return existing.result
}
if (existing === 'mismatched-key') {
throw new Error('matching key was missing from returned data. make sure arguments match between the client and server')
}
}
// @ts-ignore webpack optimization
......@@ -38,6 +44,10 @@ export function createHook(fetcher: (...args: Args[]) => Promise<any>, options:
accept: 'application/amp.bind+json',
},
}).then((res: any) => res.json()).then((result: any) => {
const hasKey = result.some((pair: [string, any]) => pair[0] === key)
if (!hasKey) {
result = [[key, 'mismatched-key']]
}
dataManager.overwrite(result)
})
throw res
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册