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

Next.js v13 programmatic API serves routes for the wrong project #42868

Open
1 task done
jaydenseric opened this issue Nov 13, 2022 · 1 comment
Open
1 task done

Next.js v13 programmatic API serves routes for the wrong project #42868

jaydenseric opened this issue Nov 13, 2022 · 1 comment
Labels
bug Issue was opened via the bug report template. stale The issue has not seen recent activity.

Comments

@jaydenseric
Copy link
Contributor

jaydenseric commented Nov 13, 2022

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 22.1.0: Sun Oct  9 20:15:09 PDT 2022; root:xnu-8792.41.9~2/RELEASE_ARM64_T6000
Binaries:
  Node: 18.12.1
  npm: 8.19.2
  Yarn: 1.22.19
  pnpm: 7.1.7
Relevant packages:
  next: 13.0.3-canary.4
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0

warn  - Latest canary version not detected, detected: "13.0.3-canary.4", newest: "13.0.3".
    Please try the latest canary version (`npm install next@canary`) to confirm the issue still exists before creating a new issue.
    Read more - https://nextjs.org/docs/messages/opening-an-issue

What browser are you using? (if relevant)

N/A

How are you deploying your application? (if relevant)

N/A

Describe the Bug

When using the Next.js JS API to programmatically create a Node.js HTTP server for one of several Next.js project directories (that have already been built via npx next build), after the first server for the first project has been started and a page has been served, if you stop that server and use the same Next.js installation to serve the second project and fetch the same route (e.g. the home page), the content of the first Next.js project that is no longer being served is incorrectly served in place of the content of the route in the second project.

This used to work correctly in Next.js v12, but is broken in Next.js v13. This issue has broken the tests for the package next-server-context; it has a fixtures folder of different kinds of Next.js projects that are one by one served for various tests using the one dev dependency installation of next.

Expected Behavior

The Next.js programatic API for serving projects should be usable for multiple Next.js projects, without whichever one that was served and fetched first corrupting the responses for later projects and requests.

Link to reproduction - Issues with a link to complete (but minimal) reproduction code will be addressed faster

N/A

To Reproduce

In package.json:

{
  "name": "demo",
  "private": true,
  "dependencies": {
    "next": "^13.0.3-canary.4",
    "react": "^18.2.0",
    "react-dom": "^18.2.0"
  }
}

In next-project-1/pages/index.js:

export default () => "Project 1 home page"

In next-project-2/pages/index.js:

export default () => "Project 2 home page"

In demo.js:

const next = require("next");
const { createServer } = require("node:http");

const httpServer1 = createServer(
  next({
    dir: "./next-project-1",
  }).getRequestHandler()
);

httpServer1.listen(async () => {
  const { port } = httpServer1.address();
  const response = await fetch(`http://localhost:${port}`);
  const html = await response.text();
  console.log(html);
  httpServer1.close();

  const httpServer2 = createServer(
    next({
      dir: "./next-project-2",
    }).getRequestHandler()
  );

  httpServer2.listen(async () => {
    const { port } = httpServer2.address();
    const response = await fetch(`http://localhost:${port}`);
    const html = await response.text();
    console.log(html);
    httpServer2.close();
  });
});

Then in Terminal:

cd next-project-1
npx next build
cd ../next-project-2
npx next build
cd ..
node demo.js

Then note that the logged homepage HTML for both projects incorrectly contains the words Project 1 home page:

Screenshot 2022-11-14 at 9 32 54 am

If you are to install next@12 instead of using Next.js v13, then the logged HTML for the project 1 home page is Project 1 home page and that of the second project is correctly Project 2 home page.

@jaydenseric jaydenseric added the bug Issue was opened via the bug report template. label Nov 13, 2022
jaydenseric added a commit to jaydenseric/next-server-context that referenced this issue Dec 16, 2022
Unable to update the `next` dev dependency to v13 yet due to this Next.js bug:

vercel/next.js#42868
@vercel-release-bot
Copy link
Collaborator

This issue has been automatically marked as stale due to two years of inactivity. It will be closed in 7 days unless there’s further input. If you believe this issue is still relevant, please leave a comment or provide updated details. Thank you.

@vercel-release-bot vercel-release-bot added the stale The issue has not seen recent activity. label Jan 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template. stale The issue has not seen recent activity.
Projects
None yet
Development

No branches or pull requests

2 participants