Skip to content

[RSC] Server Function files are split into 2 separate modules #10133

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

Open
uinz opened this issue Apr 11, 2025 · 2 comments
Open

[RSC] Server Function files are split into 2 separate modules #10133

uinz opened this issue Apr 11, 2025 · 2 comments

Comments

@uinz
Copy link

uinz commented Apr 11, 2025

I understand that the Server Function should only register the reference relationship during compilation and should not be split into multiple files.

This means that the memory state on the server side has multiple copies.

Waku's behavior is as expected

Here is an example to reproduce the problem

repo

🌍 Your Environment

Software Version(s)
Parcel 19.1.0
Node 22
npm/Yarn pnpm 8/10
Operating System linux/mac
@uinz
Copy link
Author

uinz commented Apr 16, 2025

Sorry, the previous codesandbox address was incorrect, I re-uploaded a github repo to illustrate the problem.

repo

Image

As shown above, state.ts is split into 2 separate modules when running in node. I think the same file should only have one module.

@uinz
Copy link
Author

uinz commented Apr 16, 2025

I think I know why!

The state.tsx file is referenced by 2 entries, generating 2 assets

One from "use server-entry"
The other from "use client-entry" -> "use server"

Normally, the IDs of the two assets should be the same, but since the ID generation depends on getEnvironmentHash, this function will use the values ​​of different contexts on package.json as hash parameters.

function getEnvironmentHash(env: Environment): string {
  return hashString(
    JSON.stringify([
      env.context,
      env.engines,
  // vvvvvvvvvvvvvvvvvvvvvvvv
      env.includeNodeModules,
  // ^^^^^^^^^^^^^^^^^^^^^^^^
      env.outputFormat,
      env.sourceType,
      env.isLibrary,
      env.shouldOptimize,
      env.shouldScopeHoist,
      env.sourceMap,
    ]),
  );
}

If use the server driver example's pacakge.json

{
  "name": "parcel-rsc-server",
  "version": "0.0.0",
  "private": true,
  "server": "dist/server.js",
  "targets": {
    "server": {
      "source": "src/server.tsx",
      "context": "react-server",

      vvvvvvvvvvvvvvvvvvvvvvvvvvvv
      "includeNodeModules": {
        "express": false
      }
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    }
  },

Because includeNodeModules will participate in hash calculation, if the client and server are inconsistent, the related env.id will be inconsistent. This will lead to the generation of 2 assets with different IDs, but they are actually the same file's asset.


I think we need a more stable env.id generation scheme for RSC scenarios

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant