MCPcopy
hub / github.com/vercel/next.js / checkHydrated

Function checkHydrated

test/lib/next-webdriver.ts:176–205  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

174 debugPrint(`Waiting hydration for ${fullUrl}`)
175
176 const checkHydrated = async () => {
177 await browser.eval(() => {
178 return new Promise<void>((callback) => {
179 // if it's not a Next.js app return
180 if (
181 !document.documentElement.innerHTML.includes('__NEXT_DATA__') &&
182 // @ts-ignore next exists on window if it's a Next.js page.
183 typeof ((window as any).next && (window as any).next.version) ===
184 'undefined'
185 ) {
186 console.log('Not a next.js page, resolving hydrate check')
187 callback()
188 }
189
190 // TODO: should we also ensure router.isReady is true
191 // by default before resolving?
192 if ((window as any).__NEXT_HYDRATED) {
193 console.log('Next.js page already hydrated')
194 callback()
195 } else {
196 let timeout = setTimeout(callback, 10 * 1000)
197 ;(window as any).__NEXT_HYDRATED_CB = function () {
198 clearTimeout(timeout)
199 console.log('Next.js hydrate callback fired')
200 callback()
201 }
202 }
203 })
204 })
205 }
206
207 try {
208 await checkHydrated()

Callers 1

webdriverFunction · 0.85

Calls 6

evalMethod · 0.80
includesMethod · 0.80
callbackFunction · 0.50
setTimeoutFunction · 0.50
clearTimeoutFunction · 0.50
logMethod · 0.45

Tested by

no test coverage detected