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

Fixes for ws isomorphism #47

Open
tegefaulkes opened this issue Nov 12, 2024 · 8 comments
Open

Fixes for ws isomorphism #47

tegefaulkes opened this issue Nov 12, 2024 · 8 comments
Assignees
Labels
development Standard development

Comments

@tegefaulkes
Copy link
Contributor

tegefaulkes commented Nov 12, 2024

Specification

While we have some isomorphism working to some degree, we're still running into issues with the deployed version of PKE. Otherwise it currently works when hosting locally.

The main issue is that some node modules are being included in the bundled client code. Even if these are not used the very existence of these imports in the client on the browser results in CORS errors trying to import them. We need to remove any chance of these imports when using the WebsocketClient entirely.

To fix this we just need to ensure that no node imports are done within any imports used by the client side code. The client side needs to be fully isomorphic however the server will not be supported within browsers.

Just skimming through the code I can see that utils.ts and WebsocketStream.ts has imports to node modules. These are also common to server and client code. We'll need to look into isomorphic wrappers for these node modules.

Additional context

Tasks

  1. Review Isomorphic changes from Pull feature: isomorphic WebSocket support #32
  2. Look into Isomorphic wrappers for node modules
  3. Look into isolating node imports from client related code.
  4. Remove polyfills from Polykey-Enterprise when this has been resolved.
@tegefaulkes tegefaulkes added the development Standard development label Nov 12, 2024
Copy link

linear bot commented Nov 12, 2024

@tegefaulkes tegefaulkes self-assigned this Nov 15, 2024
@aryanjassal aryanjassal changed the title Fixes for ws isomorphism Fixes for ws isomorphism Nov 21, 2024
Copy link
Member

In many cases, I prefer to just write out the utility functions they need if they are simple enough. What are the functions/constants that are required?

@CMCDragonkai
Copy link
Member

This is affecting https://github.com/MatrixAI/Polykey-Enterprise/issues/112.

Because js-ws is being used in the frontend and thus bundled. It's relying on remix vite configuration to alias certain imports, which atm is just passing through whatever is the implementation in the browser. This isn't safe, cause you're relying on environmental context, which is very browser specific (and version specific).

Most things here should be replaceable with inlined implementations, some basic functionalities can use the browserify versions...

This is a common problem with using npm dependencies that were developed for the node runtime. Generally the idea is that if the node runtime does provide it, you want to continue using it, rather than bringing your own implementation since it keeps the library minimal.

However when you are expecting to use it in the browser too, then in our case, where we can inline things, we should, where we can't, we can substitute the dependency with something conditionally. That usually is why in our package.json has browser field: https://stackoverflow.com/a/74240581.

That is a hint to the bundler to use that version instead, in particular see this: https://github.com/defunctzombie/package-browser-field-spec?tab=readme-ov-file#replace-specific-files---advanced.

Note that doing so should require the CI to simulate a browser environment too for testing.

@CMCDragonkai
Copy link
Member

Note that we should not require https://github.com/cyco130/vite-plugin-cjs-interop if this package is changed to ESM.

@CMCDragonkai
Copy link
Member

Sorry I mean https://github.com/matrixai/js-rpc is turned into ESM.

It should be possible now none of its dependencies are not ESM.

@CMCDragonkai
Copy link
Member

I raised an issue MatrixAI/js-rpc#78 in, it is not really related to this problem.

@CMCDragonkai
Copy link
Member

@CMCDragonkai
Copy link
Member

We need a corresponding issue here for js-rpc since it is pushing a bunch of hacks onto PKE as per https://github.com/MatrixAI/Polykey-Enterprise/pull/113

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

No branches or pull requests

2 participants