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

Use case: co-locating server and client code #80

Open
nicolo-ribaudo opened this issue May 14, 2023 · 4 comments
Open

Use case: co-locating server and client code #80

nicolo-ribaudo opened this issue May 14, 2023 · 4 comments

Comments

@nicolo-ribaudo
Copy link
Member

nicolo-ribaudo commented May 14, 2023

Different frameworks are moving towards co-location of code that runs on the server and on the client. Some examples are React with "use server"/"use client", Qwik with server$, and Solid with server$.

They all use functions, that can have confusing behaviors because they can close over variables "from the server to the client" and vice versa. Module expression would give a clear boundary:

// Rendered on server
function MyButton() {
  return (
    <button onClick={module {
      // Running on client
      export default () => alert("Clicked!");
    }>
      {fs.readFileSync("./btn-text")}
    </button>
  );
}

This might be another good use case for the shorthand syntax (#59)

(cc @ryansolid thanks for the idea!)

@voxpelli
Copy link

Related: #61

@littledan
Copy link
Member

Honestly I think this would be better with module declarations. It would certainly be nice to have for us in Bloomberg for this purpose. tc39/proposal-module-declarations#14

@guybedford
Copy link

Afaict, this use case would effectively require a toString() returning the source of the module? That seems doable and not a security concern (since the security concern is the reverse - creating modules from strings), but just needs to be specified?

@guybedford
Copy link

Perhaps this use case also requires context extraction, ie URL extraction? That's where it might get more difficult to specify short of a getImportMeta().

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

4 participants