Skip to content

Introducing Multi-threading - #487

Open
vezaynk wants to merge 59 commits into
gadget-inc:mainfrom
vezaynk:main
Open

vezaynk wants to merge 59 commits into
gadget-inc:mainfrom
vezaynk:main

Conversation

@vezaynk

@vezaynk vezaynk commented May 5, 2023 •

Copy link
Copy Markdown
Contributor

Introducing multi-threading to off-load React SSR to work threads.

  • Multi-threaded rendering available in production mode only.
  • Worker pooling is setup using resource-pooler
  • Transform All hooks are no longer a function, but a path to import a function to use

I will leave comments on the diff discussing every important part for easier reviewing

Todos:

  • make nonces work
  • unit tests for hooks

Comment thread packages/fastify-renderer/package.json Outdated
Comment thread packages/fastify-renderer/package.json Outdated
Comment thread packages/fastify-renderer/src/client/tsconfig.json
Comment thread packages/fastify-renderer/src/node/Plugin.ts
Comment thread packages/fastify-renderer/src/node/renderers/react/ReactRenderer.tsx Outdated
Comment thread packages/fastify-renderer/src/node/types.ts Outdated
Comment thread packages/fastify-renderer/test/renderers/ReactRenderer.spec.ts
Comment thread packages/fastify-renderer/test/routes.spec.ts Outdated
Comment thread packages/test-apps/simple-react/server.ts
Comment thread packages/fastify-renderer/package.json Outdated
Comment thread packages/fastify-renderer/package.json Outdated
Comment thread packages/fastify-renderer/src/node/Plugin.ts
Comment thread packages/fastify-renderer/src/node/renderers/react/ReactRenderer.tsx Outdated
Comment thread packages/fastify-renderer/src/node/renderers/react/ReactRenderer.tsx Outdated
Comment thread packages/fastify-renderer/test/routes.spec.ts Outdated
@vezaynk

vezaynk commented May 8, 2023

Copy link
Copy Markdown
Contributor Author

I'm updating most dev dependencies to make the linter accept satisfies.

@vezaynk

vezaynk commented May 8, 2023

Copy link
Copy Markdown
Contributor Author

@airhorns wds needs to have a version bump to @swc/core applied. satisfies doesn't build without it.

Comment thread packages/fastify-renderer/test/routes.spec.ts Outdated
Comment thread packages/fastify-renderer/test/routes.spec.ts
transpileOnly: true,
})
require(tsWorkerPath)
} catch {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this catch is going to catch any errors importing the actual target file, like syntax errors or runtime issues. Could we drive the decision to use ts-node or not with an environment variable or some other explicit instruction?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think magic flags should be avoided imo, especially given that it only matters in development of this package itself.

.ts files will never appear in the built package, which will make this always throw when distributed, and always load the js file instead.

It's safe in that respect.

I can do it based on the existence of a .ts file instead. Would that be better?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@airhorns Actually this can be handled really nicely via vite, but I can't do that right now because the test app doesn't use vite. It could be a small project for later if you like.

Comment thread packages/fastify-renderer/test/routes.spec.ts Outdated
Comment thread package.json
Comment thread packages/fastify-renderer/src/node/Plugin.ts
Comment thread packages/fastify-renderer/src/node/RenderBus.tsx Outdated
@vezaynk
vezaynk requested a review from airhorns November 19, 2023 19:02
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

Successfully merging this pull request may close these issues.

2 participants