Unverified Commit a4438fe8 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Remove invalid app router etag normalizing (#68948)

This didn't end up achieving the normalizing we were hoping for as the
react bump after this was landed causes indeterminism even with this
fix. This needs to be resolved upstream in react itself so removing our
attempted patch and failing assertion in the mean-time.
parent 4e4632c2
......@@ -68,52 +68,10 @@ export async function sendRenderResult({
})
)
}
const payload = result.isDynamic ? null : result.toUnchunkedString()
if (payload !== null) {
let etagPayload = payload
if (type === 'rsc') {
// ensure etag generation is deterministic as
// ordering can differ even if underlying content
// does not differ
etagPayload = payload.split('\n').sort().join('\n')
} else if (type === 'html' && payload.includes('__next_f')) {
const { parse } =
require('next/dist/compiled/node-html-parser') as typeof import('next/dist/compiled/node-html-parser')
try {
// Parse the HTML
let root = parse(payload)
// Get script tags in the body element
let scriptTags = root
.querySelector('body')
?.querySelectorAll('script')
.filter(
(node) =>
!node.hasAttribute('src') && node.innerHTML?.includes('__next_f')
)
// Sort the script tags by their inner text
scriptTags?.sort((a, b) => a.innerHTML.localeCompare(b.innerHTML))
// Remove the original script tags
scriptTags?.forEach((script: any) => script.remove())
// Append the sorted script tags to the body
scriptTags?.forEach((script: any) =>
root.querySelector('body')?.appendChild(script)
)
// Stringify back to HTML
etagPayload = root.toString()
} catch (err) {
console.error(`Error parsing HTML payload`, err)
}
}
const etag = generateEtags ? generateETag(etagPayload) : undefined
if (generateEtags && payload !== null) {
const etag = generateETag(payload)
if (sendEtagResponse(req, res, etag)) {
return
}
......
......@@ -697,37 +697,6 @@ describe('app-dir static/dynamic handling', () => {
})
if (isNextStart) {
it.failing(
'should have deterministic etag across revalidates',
async () => {
const initialRes = await next.fetch(
'/variable-revalidate-stable/revalidate-3'
)
expect(initialRes.status).toBe(200)
// check 2 revalidate passes to ensure it's consistent
for (let i = 0; i < 2; i++) {
let startIdx = next.cliOutput.length
await retry(
async () => {
const res = await next.fetch(
'/variable-revalidate-stable/revalidate-3'
)
expect(next.cliOutput.substring(startIdx)).toContain(
'rendering /variable-revalidate-stable'
)
expect(initialRes.headers.get('etag')).toBe(
res.headers.get('etag')
)
},
12_000,
3_000
)
}
}
)
it('should output HTML/RSC files for static paths', async () => {
const files = (
await glob('**/*', {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment