1
0
mirror of synced 2025-12-25 02:17:36 -05:00

return 404 on /_next.junk (#33770)

This commit is contained in:
Peter Bengtsson
2023-01-06 02:12:58 +01:00
committed by GitHub
parent 3d1f0f10de
commit c49557775e
3 changed files with 26 additions and 12 deletions

View File

@@ -1,4 +1,4 @@
import React, { useEffect } from 'react'
import { useEffect } from 'react'
import App from 'next/app'
import type { AppProps, AppContext } from 'next/app'
import Head from 'next/head'
@@ -111,17 +111,23 @@ MyApp.getInitialProps = async (appContext: AppContext) => {
const languagesContext: LanguagesContextT = {
languages: {},
}
for (const [langCode, langObj] of Object.entries(
req.context.languages as Record<string, LanguageItem>
)) {
if (langObj.wip) continue
// Only pick out the keys we actually need
languagesContext.languages[langCode] = {
name: langObj.name,
code: langObj.code,
}
if (langObj.nativeName) {
languagesContext.languages[langCode].nativeName = langObj.nativeName
// If we're rendering certain 404 error pages, the middleware might not
// yet have contextualized the `context.languages`. So omit this
// context mutation and live without it.
if (req.context.languages) {
for (const [langCode, langObj] of Object.entries(
req.context.languages as Record<string, LanguageItem>
)) {
if (langObj.wip) continue
// Only pick out the keys we actually need
languagesContext.languages[langCode] = {
name: langObj.name,
code: langObj.code,
}
if (langObj.nativeName) {
languagesContext.languages[langCode].nativeName = langObj.nativeName
}
}
}