Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix module error for findDOMNode on edge #43998

Merged
merged 3 commits into from Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 7 additions & 6 deletions packages/next/client/components/layout-router.tsx
Expand Up @@ -9,10 +9,11 @@ import type {
} from '../../server/app-render'
import type { ErrorComponent } from './error-boundary'
import type { FocusAndScrollRef } from './reducer'
import type { findDOMNode as TFindDOMNode } from 'react-dom'
huozhi marked this conversation as resolved.
Show resolved Hide resolved
import type { ChildProp } from '../../server/app-render'

import React, { useContext, useEffect, use } from 'react'
import { findDOMNode as ReactDOMfindDOMNode } from 'react-dom'
import type { ChildProp } from '../../server/app-render'
import ReactDOM from 'react-dom'
import {
CacheStates,
LayoutRouterContext,
Expand Down Expand Up @@ -80,8 +81,8 @@ function walkAddRefetch(
* Wraps ReactDOM.findDOMNode with additional logic to hide React Strict Mode warning
*/
function findDOMNode(
instance: Parameters<typeof ReactDOMfindDOMNode>[0]
): ReturnType<typeof ReactDOMfindDOMNode> {
instance: Parameters<typeof TFindDOMNode>[0]
huozhi marked this conversation as resolved.
Show resolved Hide resolved
): ReturnType<typeof TFindDOMNode> {
// Only apply strict mode warning when not in production
if (process.env.NODE_ENV !== 'production') {
const originalConsoleError = console.error
Expand All @@ -92,12 +93,12 @@ function findDOMNode(
originalConsoleError(...messages)
}
}
return ReactDOMfindDOMNode(instance)
return ReactDOM.findDOMNode(instance)
} finally {
console.error = originalConsoleError!
}
}
return ReactDOMfindDOMNode(instance)
return ReactDOM.findDOMNode(instance)
}

/**
Expand Down
16 changes: 13 additions & 3 deletions test/e2e/app-dir/app-edge.test.ts
Expand Up @@ -34,6 +34,17 @@ describe('app-dir edge SSR', () => {
})

if ((globalThis as any).isNextDev) {
it('should resolve module without error in edge runtime', async () => {
const logs = []
next.on('stderr', (log) => {
logs.push(log)
})
await renderViaHTTP(next.url, 'app-edge')
expect(logs.some((log) => log.includes(`Attempted import error:`))).toBe(
false
)
})

it('should handle edge rsc hmr', async () => {
const pageFile = 'app/app-edge/page.tsx'
const content = await next.readFile(pageFile)
Expand All @@ -53,9 +64,8 @@ describe('app-dir edge SSR', () => {
return html
}, /Edge!/)
})
}

if (!(globalThis as any).isNextDev) {
} else {
// Production tests
it('should generate matchers correctly in middleware manifest', async () => {
const manifest = JSON.parse(
await next.readFile('.next/server/middleware-manifest.json')
Expand Down
8 changes: 0 additions & 8 deletions test/e2e/streaming-ssr/index.test.ts
Expand Up @@ -10,11 +10,6 @@ import {
renderViaHTTP,
} from 'next-test-utils'

const react18Deps = {
react: '^18.0.0',
'react-dom': '^18.0.0',
}

const isNextProd = !(global as any).isNextDev && !(global as any).isNextDeploy

describe('streaming SSR with custom next configs', () => {
Expand All @@ -31,7 +26,6 @@ describe('streaming SSR with custom next configs', () => {
pages: new FileRef(join(__dirname, 'streaming-ssr/pages')),
},
nextConfig: require(join(__dirname, 'streaming-ssr/next.config.js')),
dependencies: react18Deps,
installCommand: 'npm install',
})
})
Expand Down Expand Up @@ -116,7 +110,6 @@ if (isNextProd) {
'server.js': new FileRef(join(__dirname, 'custom-server/server.js')),
},
nextConfig: require(join(__dirname, 'custom-server/next.config.js')),
dependencies: react18Deps,
})
await next.stop()

Expand Down Expand Up @@ -185,7 +178,6 @@ if (isNextProd) {
return config
},
},
dependencies: react18Deps,
})
})
afterAll(() => {
Expand Down
4 changes: 1 addition & 3 deletions test/e2e/streaming-ssr/streaming-ssr/pages/router.js
Expand Up @@ -6,6 +6,4 @@ export default () => {
return <Link href="/">link</Link>
}

export const config = {
runtime: 'experimental-edge',
}
export const config = { runtime: 'experimental-edge' }