mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
Currently we create separate workers to isolate `pages` and `app` routers due to differing react versions being used between the two. This adds overhead and complexity in the rendering process which we can avoid by leveraging an `esm-loader` similar to our `require-hook` to properly alias `pages` router to the bundled react version to match `app` router when both are leveraged together. This aims to seamlessly inject the `esm-loader` by restarting the process with the loader arg added whenever `next` is imported so that this also works with custom-servers and fixes the issue with custom req/res fields not working after upgrading. x-ref: https://github.com/vercel/next.js/issues/53883 x-ref: https://github.com/vercel/next.js/issues/54288 x-ref: https://github.com/vercel/next.js/issues/54129 x-ref: https://github.com/vercel/next.js/issues/54435 closes: https://github.com/vercel/next.js/issues/54440 closes: https://github.com/vercel/next.js/issues/52702 x-ref: [slack thread](https://vercel.slack.com/archives/C03KAR5DCKC/p1693348443932499?thread_ts=1693275196.347509&cid=C03KAR5DCKC) --------- Co-authored-by: Tim Neutkens <[email protected]> Co-authored-by: Zack Tanner <[email protected]> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
173 lines
6.4 KiB
TypeScript
173 lines
6.4 KiB
TypeScript
import { join } from 'path'
|
|
import { createNextDescribe } from 'e2e-utils'
|
|
|
|
createNextDescribe(
|
|
'node builtins',
|
|
{
|
|
files: join(__dirname, 'node-builtins'),
|
|
},
|
|
({ next }) => {
|
|
it('should have polyfilled node.js builtins for the browser correctly', async () => {
|
|
const browser = await next.browser('/')
|
|
|
|
await browser.waitForCondition('window.didRender', 15000)
|
|
|
|
const data = await browser
|
|
.waitForElementByCss('#node-browser-polyfills')
|
|
.text()
|
|
const parsedData = JSON.parse(data)
|
|
|
|
expect(parsedData.vm).toBe(105)
|
|
expect(parsedData.hash).toBe(
|
|
'b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9'
|
|
)
|
|
expect(parsedData.buffer).toBe('hello world')
|
|
expect(parsedData.stream).toBe(true)
|
|
expect(parsedData.assert).toBe(true)
|
|
expect(parsedData.constants).toBe(7)
|
|
expect(parsedData.domain).toBe(true)
|
|
expect(parsedData.http).toBe(true)
|
|
expect(parsedData.https).toBe(true)
|
|
expect(parsedData.os).toBe('\n')
|
|
expect(parsedData.path).toBe('/hello/world/test.txt')
|
|
expect(parsedData.process).toBe('browser')
|
|
expect(parsedData.querystring).toBe('a=b')
|
|
expect(parsedData.stringDecoder).toBe(true)
|
|
expect(parsedData.sys).toBe(true)
|
|
expect(parsedData.timers).toBe(true)
|
|
})
|
|
|
|
it('should have polyfilled node.js builtins for the browser correctly in client component', async () => {
|
|
const browser = await next.browser('/client-component')
|
|
|
|
await browser.waitForCondition('window.didRender', 15000)
|
|
|
|
const data = await browser
|
|
.waitForElementByCss('#node-browser-polyfills')
|
|
.text()
|
|
const parsedData = JSON.parse(data)
|
|
|
|
expect(parsedData.vm).toBe(105)
|
|
expect(parsedData.hash).toBe(
|
|
'b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9'
|
|
)
|
|
expect(parsedData.buffer).toBe('hello world')
|
|
expect(parsedData.stream).toBe(true)
|
|
expect(parsedData.assert).toBe(true)
|
|
expect(parsedData.constants).toBe(7)
|
|
expect(parsedData.domain).toBe(true)
|
|
expect(parsedData.http).toBe(true)
|
|
expect(parsedData.https).toBe(true)
|
|
expect(parsedData.os).toBe('\n')
|
|
expect(parsedData.path).toBe('/hello/world/test.txt')
|
|
expect(parsedData.process).toBe('browser')
|
|
expect(parsedData.querystring).toBe('a=b')
|
|
expect(parsedData.stringDecoder).toBe(true)
|
|
expect(parsedData.sys).toBe(true)
|
|
expect(parsedData.timers).toBe(true)
|
|
})
|
|
|
|
it('should support node.js builtins', async () => {
|
|
const $ = await next.render$('/server')
|
|
|
|
const data = $('#node-browser-polyfills').text()
|
|
const parsedData = JSON.parse(data)
|
|
|
|
expect(parsedData.vm).toBe(105)
|
|
expect(parsedData.hash).toBe(
|
|
'b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9'
|
|
)
|
|
expect(parsedData.buffer).toBe('hello world')
|
|
expect(parsedData.stream).toBe(true)
|
|
expect(parsedData.assert).toBe(true)
|
|
expect(parsedData.constants).toBe(7)
|
|
expect(parsedData.domain).toBe(true)
|
|
expect(parsedData.http).toBe(true)
|
|
expect(parsedData.https).toBe(true)
|
|
expect(parsedData.os).toBe('\n')
|
|
expect(parsedData.path).toBe('/hello/world/test.txt')
|
|
expect(parsedData.process).toInclude('next-router-worker')
|
|
expect(parsedData.querystring).toBe('a=b')
|
|
expect(parsedData.stringDecoder).toBe(true)
|
|
expect(parsedData.sys).toBe(true)
|
|
expect(parsedData.timers).toBe(true)
|
|
})
|
|
|
|
it('should support node.js builtins prefixed by node:', async () => {
|
|
const $ = await next.render$('/server-node-schema')
|
|
|
|
const data = $('#node-browser-polyfills').text()
|
|
const parsedData = JSON.parse(data)
|
|
|
|
expect(parsedData.vm).toBe(105)
|
|
expect(parsedData.hash).toBe(
|
|
'b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9'
|
|
)
|
|
expect(parsedData.buffer).toBe('hello world')
|
|
expect(parsedData.stream).toBe(true)
|
|
expect(parsedData.assert).toBe(true)
|
|
expect(parsedData.constants).toBe(7)
|
|
expect(parsedData.domain).toBe(true)
|
|
expect(parsedData.http).toBe(true)
|
|
expect(parsedData.https).toBe(true)
|
|
expect(parsedData.os).toBe('\n')
|
|
expect(parsedData.path).toBe('/hello/world/test.txt')
|
|
expect(parsedData.process).toInclude('next-router-worker')
|
|
expect(parsedData.querystring).toBe('a=b')
|
|
expect(parsedData.stringDecoder).toBe(true)
|
|
expect(parsedData.sys).toBe(true)
|
|
expect(parsedData.timers).toBe(true)
|
|
})
|
|
|
|
it('should support node.js builtins in server component', async () => {
|
|
const $ = await next.render$('/server-component')
|
|
|
|
const data = $('#node-browser-polyfills').text()
|
|
const parsedData = JSON.parse(data)
|
|
|
|
expect(parsedData.vm).toBe(105)
|
|
expect(parsedData.hash).toBe(
|
|
'b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9'
|
|
)
|
|
expect(parsedData.buffer).toBe('hello world')
|
|
expect(parsedData.stream).toBe(true)
|
|
expect(parsedData.assert).toBe(true)
|
|
expect(parsedData.constants).toBe(7)
|
|
expect(parsedData.domain).toBe(true)
|
|
expect(parsedData.http).toBe(true)
|
|
expect(parsedData.https).toBe(true)
|
|
expect(parsedData.os).toBe('\n')
|
|
expect(parsedData.path).toBe('/hello/world/test.txt')
|
|
expect(parsedData.querystring).toBe('a=b')
|
|
expect(parsedData.stringDecoder).toBe(true)
|
|
expect(parsedData.sys).toBe(true)
|
|
expect(parsedData.timers).toBe(true)
|
|
})
|
|
|
|
it('should support node.js builtins prefixed by node: in server component', async () => {
|
|
const $ = await next.render$('/server-component/node-schema')
|
|
|
|
const data = $('#node-browser-polyfills').text()
|
|
const parsedData = JSON.parse(data)
|
|
|
|
expect(parsedData.vm).toBe(105)
|
|
expect(parsedData.hash).toBe(
|
|
'b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9'
|
|
)
|
|
expect(parsedData.buffer).toBe('hello world')
|
|
expect(parsedData.stream).toBe(true)
|
|
expect(parsedData.assert).toBe(true)
|
|
expect(parsedData.constants).toBe(7)
|
|
expect(parsedData.domain).toBe(true)
|
|
expect(parsedData.http).toBe(true)
|
|
expect(parsedData.https).toBe(true)
|
|
expect(parsedData.os).toBe('\n')
|
|
expect(parsedData.path).toBe('/hello/world/test.txt')
|
|
expect(parsedData.querystring).toBe('a=b')
|
|
expect(parsedData.stringDecoder).toBe(true)
|
|
expect(parsedData.sys).toBe(true)
|
|
expect(parsedData.timers).toBe(true)
|
|
})
|
|
}
|
|
)
|