Skip to content

Commit

Permalink
Another batch of wrong imports
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Apr 21, 2024
1 parent f3e8d3e commit a749287
Show file tree
Hide file tree
Showing 13 changed files with 100 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ export function createServerReference(id: string) {
const { createServerReference: createServerReferenceImpl } = (
!!process.env.NEXT_RUNTIME
? // eslint-disable-next-line import/no-extraneous-dependencies
require('react-server-dom-webpack/client.edge')
require('next/dist/compiled/react-server-dom-webpack/client.edge')
: // eslint-disable-next-line import/no-extraneous-dependencies
require('react-server-dom-webpack/client')
) as typeof import('react-server-dom-webpack/client')
require('next/dist/compiled/react-server-dom-webpack/client')
) as typeof import('next/dist/compiled/react-server-dom-webpack/client')

return createServerReferenceImpl(id, callServer)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
// import { createFromFetch } from 'next/dist/compiled/react-server-dom-webpack/client'
const { createFromFetch } = (
!!process.env.NEXT_RUNTIME
? // eslint-disable-next-line import/no-extraneous-dependencies
require('react-server-dom-webpack/client.edge')
: // eslint-disable-next-line import/no-extraneous-dependencies
require('react-server-dom-webpack/client')
) as typeof import('react-server-dom-webpack/client')
? require('next/dist/compiled/react-server-dom-webpack/client.edge')
: require('next/dist/compiled/react-server-dom-webpack/client')
) as typeof import('next/dist/compiled/react-server-dom-webpack/client')

import type {
FlightRouterState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import {
const { createFromFetch, encodeReply } = (
!!process.env.NEXT_RUNTIME
? // eslint-disable-next-line import/no-extraneous-dependencies
require('react-server-dom-webpack/client.edge')
require('next/dist/compiled/react-server-dom-webpack/client.edge')
: // eslint-disable-next-line import/no-extraneous-dependencies
require('react-server-dom-webpack/client')
) as typeof import('react-server-dom-webpack/client')
require('next/dist/compiled/react-server-dom-webpack/client')
) as typeof import('next/dist/compiled/react-server-dom-webpack/client')

import type {
ReadonlyReducerState,
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/server/app-render/app-render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1241,7 +1241,7 @@ async function renderToHTMLOrFlightImpl(

try {
const fizzStream = await renderToInitialFizzStream({
ReactDOMServer: require('react-dom/server.edge'),
ReactDOMServer: require('next/dist/compiled/react-dom/server.edge'),
element: (
<ReactServerEntrypoint
reactServerStream={errorServerStream}
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/server/app-render/render-to-string.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export async function renderToString({
ReactDOMServer,
element,
}: {
ReactDOMServer: typeof import('react-dom/server.edge')
ReactDOMServer: typeof import('next/dist/compiled/react-dom/server.edge')
element: React.ReactElement
}) {
return getTracer().trace(AppRenderSpan.renderToString, async () => {
Expand Down
13 changes: 7 additions & 6 deletions packages/next/src/server/app-render/static/static-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export interface Renderer {
class StaticRenderer implements Renderer {
// this is for tree shaking. Couldn't find a better way to do it for some reason
private readonly prerender = (process.env.__NEXT_EXPERIMENTAL_REACT
? require('react-dom/static.edge').prerender
: null) as typeof import('react-dom/static.edge')['prerender']
? require('next/dist/compiled/react-dom/static.edge').prerender
: null) as typeof import('next/dist/compiled/react-dom/static.edge')['prerender']

constructor(private readonly options: PrerenderOptions) {}

Expand All @@ -30,8 +30,8 @@ class StaticRenderer implements Renderer {
}

class StaticResumeRenderer implements Renderer {
private readonly resume = require('react-dom/server.edge')
.resume as typeof import('react-dom/server.edge')['resume']
private readonly resume = require('next/dist/compiled/react-dom/server.edge')
.resume as typeof import('next/dist/compiled/react-dom/server.edge')['resume']

constructor(
private readonly postponed: object,
Expand All @@ -46,8 +46,9 @@ class StaticResumeRenderer implements Renderer {
}

export class ServerRenderer implements Renderer {
private readonly renderToReadableStream = require('react-dom/server.edge')
.renderToReadableStream as typeof import('react-dom/server.edge')['renderToReadableStream']
private readonly renderToReadableStream =
require('next/dist/compiled/react-dom/server.edge')
.renderToReadableStream as typeof import('next/dist/compiled/react-dom/server.edge')['renderToReadableStream']

constructor(private readonly options: RenderToReadableStreamOptions) {}

Expand Down
6 changes: 2 additions & 4 deletions packages/next/src/server/app-render/use-flight-response.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,10 @@ export function useFlightStream<T>(
// @TODO: investigate why the aliasing for turbopack doesn't pick this up, requiring this runtime check
if (process.env.TURBOPACK) {
createFromReadableStream =
// eslint-disable-next-line import/no-extraneous-dependencies
require('react-server-dom-turbopack/client.edge').createFromReadableStream
require('next/dist/compiled/react-server-dom-turbopack/client.edge').createFromReadableStream
} else {
createFromReadableStream =
// eslint-disable-next-line import/no-extraneous-dependencies
require('react-server-dom-webpack/client.edge').createFromReadableStream
require('next/dist/compiled/react-server-dom-webpack/client.edge').createFromReadableStream
}

const newResponse = createFromReadableStream(flightStream, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import * as ReactJsxRuntime from 'next/dist/compiled/react/jsx-runtime'
function getAltProxyForBindingsDEV(
type: 'Turbopack' | 'Webpack',
pkg:
| 'react-server-dom-turbopack/server.edge'
| 'react-server-dom-turbopack/server.node'
| 'react-server-dom-webpack/server.edge'
| 'react-server-dom-webpack/server.node'
| 'next/dist/compiled/react-server-dom-turbopack/server.edge'
| 'next/dist/compiled/react-server-dom-turbopack/server.node'
| 'next/dist/compiled/react-server-dom-webpack/server.edge'
| 'next/dist/compiled/react-server-dom-webpack/server.node'
) {
if (process.env.NODE_ENV === 'development') {
const altType = type === 'Turbopack' ? 'Webpack' : 'Turbopack'
Expand All @@ -33,36 +33,33 @@ let ReactServerDOMTurbopackServerNode, ReactServerDOMWebpackServerNode

if (process.env.TURBOPACK) {
// eslint-disable-next-line import/no-extraneous-dependencies
ReactServerDOMTurbopackServerEdge = require('react-server-dom-turbopack/server.edge')
ReactServerDOMTurbopackServerEdge = require('next/dist/compiled/react-server-dom-turbopack/server.edge')
if (process.env.NODE_ENV === 'development') {
ReactServerDOMWebpackServerEdge = getAltProxyForBindingsDEV(
'Turbopack',
'react-server-dom-turbopack/server.edge'
'next/dist/compiled/react-server-dom-turbopack/server.edge'
)
}
// eslint-disable-next-line import/no-extraneous-dependencies
ReactServerDOMTurbopackServerNode = require('react-server-dom-turbopack/server.node')
ReactServerDOMTurbopackServerNode = require('next/dist/compiled/react-server-dom-turbopack/server.node')
if (process.env.NODE_ENV === 'development') {
ReactServerDOMWebpackServerNode = getAltProxyForBindingsDEV(
'Turbopack',
'react-server-dom-turbopack/server.node'
'next/dist/compiled/react-server-dom-turbopack/server.node'
)
}
} else {
// eslint-disable-next-line import/no-extraneous-dependencies
ReactServerDOMWebpackServerEdge = require('react-server-dom-webpack/server.edge')
ReactServerDOMWebpackServerEdge = require('next/dist/compiled/react-server-dom-webpack/server.edge')
if (process.env.NODE_ENV === 'development') {
ReactServerDOMTurbopackServerEdge = getAltProxyForBindingsDEV(
'Webpack',
'react-server-dom-webpack/server.edge'
'next/dist/compiled/react-server-dom-webpack/server.edge'
)
}
// eslint-disable-next-line import/no-extraneous-dependencies
ReactServerDOMWebpackServerNode = require('react-server-dom-webpack/server.node')
ReactServerDOMWebpackServerNode = require('next/dist/compiled/react-server-dom-webpack/server.node')
if (process.env.NODE_ENV === 'development') {
ReactServerDOMTurbopackServerNode = getAltProxyForBindingsDEV(
'Webpack',
'react-server-dom-webpack/server.node'
'next/dist/compiled/react-server-dom-webpack/server.node'
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ import * as React from 'next/dist/compiled/react'
import * as ReactDOM from 'next/dist/compiled/react-dom/server-rendering-stub'
import * as ReactJsxDevRuntime from 'next/dist/compiled/react/jsx-dev-runtime'
import * as ReactJsxRuntime from 'next/dist/compiled/react/jsx-runtime'

// eslint-disable-next-line import/no-extraneous-dependencies
import * as ReactDOMServerEdge from 'next/dist/compiled/react-dom/server.edge'

function getAltProxyForBindingsDEV(
type: 'Turbopack' | 'Webpack',
pkg:
| 'react-server-dom-turbopack/client.edge'
| 'react-server-dom-webpack/client.edge'
| 'next/dist/compiled/react-server-dom-turbopack/client.edge'
| 'next/dist/compiled/react-server-dom-webpack/client.edge'
) {
if (process.env.NODE_ENV === 'development') {
const altType = type === 'Turbopack' ? 'Webpack' : 'Turbopack'
Expand All @@ -31,21 +29,19 @@ function getAltProxyForBindingsDEV(

let ReactServerDOMTurbopackClientEdge, ReactServerDOMWebpackClientEdge
if (process.env.TURBOPACK) {
// eslint-disable-next-line import/no-extraneous-dependencies
ReactServerDOMTurbopackClientEdge = require('react-server-dom-turbopack/client.edge')
ReactServerDOMTurbopackClientEdge = require('next/dist/compiled/react-server-dom-turbopack/client.edge')
if (process.env.NODE_ENV === 'development') {
ReactServerDOMWebpackClientEdge = getAltProxyForBindingsDEV(
'Turbopack',
'react-server-dom-turbopack/client.edge'
'next/dist/compiled/react-server-dom-turbopack/client.edge'
)
}
} else {
// eslint-disable-next-line import/no-extraneous-dependencies
ReactServerDOMWebpackClientEdge = require('react-server-dom-webpack/client.edge')
ReactServerDOMWebpackClientEdge = require('next/dist/compiled/react-server-dom-webpack/client.edge')
if (process.env.NODE_ENV === 'development') {
ReactServerDOMTurbopackClientEdge = getAltProxyForBindingsDEV(
'Webpack',
'react-server-dom-webpack/client.edge'
'next/dist/compiled/react-server-dom-webpack/client.edge'
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export function renderToInitialFizzStream({
element,
streamOptions,
}: {
ReactDOMServer: typeof import('react-dom/server.edge')
ReactDOMServer: typeof import('next/dist/compiled/react-dom/server.edge')
element: React.ReactElement
streamOptions?: any
}): Promise<ReactReadableStream> {
Expand Down
33 changes: 26 additions & 7 deletions packages/next/types/$$compiled.internal.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@ declare module 'next/dist/compiled/react-server-dom-turbopack/server.browser'
declare module 'next/dist/compiled/react-server-dom-turbopack/server.edge'
declare module 'next/dist/client/app-call-server'
declare module 'next/dist/compiled/react-dom/server'
declare module 'next/dist/compiled/react-dom/server.edge'
declare module 'next/dist/compiled/react-dom/server.browser'
declare module 'next/dist/compiled/browserslist'

declare module 'react-server-dom-webpack/client'
declare module 'react-server-dom-webpack/server.edge'
declare module 'react-server-dom-webpack/server.node'
declare module 'react-server-dom-webpack/client.edge'
declare module 'next/dist/compiled/react-server-dom-webpack/client'
declare module 'next/dist/compiled/react-server-dom-webpack/server.edge'
declare module 'next/dist/compiled/react-server-dom-webpack/server.node'
declare module 'next/dist/compiled/react-server-dom-webpack/client.edge'

declare module 'VAR_MODULE_GLOBAL_ERROR'
declare module 'VAR_USERLAND'
Expand Down Expand Up @@ -355,14 +354,34 @@ declare module 'next/dist/compiled/@edge-runtime/primitives' {
}

declare module 'next/dist/compiled/react' {
import * as m from 'next/dist/compiled/react'
import * as m from 'react'
export = m
}

declare module 'next/dist/compiled/react/jsx-runtime' {
import * as m from 'react/jsx-runtime'
export = m
}

declare module 'next/dist/compiled/react/jsx-dev-runtime' {
import * as m from 'react/jsx-dev-runtime'
export = m
}

declare module 'next/dist/compiled/react-dom' {
import * as m from 'next/dist/compiled/react-dom'
import * as m from 'react-dom'
export = m
}

declare module 'next/dist/compiled/react-dom/client' {
import * as m from 'react-dom/client'
export = m
}

declare module 'next/dist/compiled/react-is' {
export * from 'react-is'
}

declare module 'next/dist/compiled/stacktrace-parser' {
import * as m from 'stacktrace-parser'
export = m
Expand Down
32 changes: 31 additions & 1 deletion packages/next/types/compiled.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,39 @@ declare module 'next/dist/compiled/superstruct' {
export type Describe<T> = any
}

declare module 'react-server-dom-webpack/server.edge'
declare module 'next/dist/compiled/react-server-dom-webpack/server.edge'

declare module 'VAR_MODULE_GLOBAL_ERROR'
declare module 'VAR_USERLAND'
declare module 'VAR_MODULE_DOCUMENT'
declare module 'VAR_MODULE_APP'

declare module 'next/dist/compiled/react' {
import * as m from 'react'
export = m
}

declare module 'next/dist/compiled/react/jsx-runtime' {
import * as m from 'react/jsx-runtime'
export = m
}

declare module 'next/dist/compiled/react/jsx-dev-runtime' {
import * as m from 'react/jsx-dev-runtime'
export = m
}

declare module 'next/dist/compiled/react-dom' {
import * as m from 'react-dom'
export = m
}

declare module 'next/dist/compiled/react-dom/client' {
import * as m from 'react-dom/client'
export = m
}

declare module 'next/dist/compiled/react-is' {
import * as m from 'react-is'
export = m
}
8 changes: 4 additions & 4 deletions packages/next/types/react-dom.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
declare module 'react-dom/server-rendering-stub'
declare module 'react-dom/server.browser'
declare module 'next/dist/compiled/react-dom/server-rendering-stub'
declare module 'next/dist/compiled/react-dom/server.browser'

declare module 'react-dom/server.edge' {
declare module 'next/dist/compiled/react-dom/server.edge' {
/**
* https://github.com/facebook/react/blob/aec521a96d3f1bebc2ba38553d14f4989c6e88e0/packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js#L329-L333
*/
Expand Down Expand Up @@ -74,7 +74,7 @@ declare module 'react-dom/server.edge' {
>
}

declare module 'react-dom/static.edge' {
declare module 'next/dist/compiled/react-dom/static.edge' {
/**
* https://github.com/facebook/react/blob/aec521a96d3f1bebc2ba38553d14f4989c6e88e0/packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js#L329-L333
*/
Expand Down

0 comments on commit a749287

Please sign in to comment.