From cfb8cc841e6c7b80e809565cddfc4219d695c282 Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Sun, 7 Nov 2021 23:14:50 +0100 Subject: [PATCH] Change .web extension of document page to part of path (#31116) Fixes: #31104 This effecting users who are using expo with next (`@expo/next-adapter`) since react-native use `.web`, `.ios` and `.android` to identify platform. [Reference](https://docs.expo.dev/guides/using-electron/#%F0%9F%A7%B8-behavior) Change `document.web.js` to `document-web.js` as fallback page in web runtime --- packages/next/build/entries.ts | 2 +- packages/next/build/webpack-config.ts | 2 +- packages/next/pages/{_document.web.tsx => _document-web.tsx} | 2 ++ packages/next/taskfile.js | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) rename packages/next/pages/{_document.web.tsx => _document-web.tsx} (85%) diff --git a/packages/next/build/entries.ts b/packages/next/build/entries.ts index be2f0b3e8236e48..e2c478c0e834c48 100644 --- a/packages/next/build/entries.ts +++ b/packages/next/build/entries.ts @@ -65,7 +65,7 @@ export function createPagesMapping( // we alias these in development and allow webpack to // allow falling back to the correct source file so // that HMR can work properly when a file is added/removed - const documentPage = `_document${hasServerComponents ? '.web' : ''}` + const documentPage = `_document${hasServerComponents ? '-web' : ''}` if (isDev) { pages['/_app'] = `${PAGES_DIR_ALIAS}/_app` pages['/_error'] = `${PAGES_DIR_ALIAS}/_error` diff --git a/packages/next/build/webpack-config.ts b/packages/next/build/webpack-config.ts index 730856f88af2440..a59784b37ddc3a0 100644 --- a/packages/next/build/webpack-config.ts +++ b/packages/next/build/webpack-config.ts @@ -629,7 +629,7 @@ export default async function getBaseWebpackConfig( prev.push(path.join(pagesDir, `_document.${ext}`)) return prev }, [] as string[]), - `next/dist/pages/_document${hasServerComponents ? '.web' : ''}.js`, + `next/dist/pages/_document${hasServerComponents ? '-web' : ''}.js`, ] } diff --git a/packages/next/pages/_document.web.tsx b/packages/next/pages/_document-web.tsx similarity index 85% rename from packages/next/pages/_document.web.tsx rename to packages/next/pages/_document-web.tsx index 92c6462ae923e50..24421541293504c 100644 --- a/packages/next/pages/_document.web.tsx +++ b/packages/next/pages/_document-web.tsx @@ -1,3 +1,5 @@ +// Default _document page for web runtime + import React from 'react' import { Html, Head, Main, NextScript } from './_document' diff --git a/packages/next/taskfile.js b/packages/next/taskfile.js index acd995ed7b17cb9..cd5c74b37d42a14 100644 --- a/packages/next/taskfile.js +++ b/packages/next/taskfile.js @@ -1123,7 +1123,7 @@ export async function pages_document(task, opts) { export async function pages_document_server(task, opts) { await task - .source('pages/_document.web.tsx') + .source('pages/_document-web.tsx') .swc('client', { dev: opts.dev }) .target('dist/pages') }