Skip to content

Introducing Multi-threading #487

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
wants to merge 59 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
4c66757
multithreading WIP
vezaynk Apr 27, 2023
a49fdff
More WIP
vezaynk Apr 27, 2023
b956569
more WIP
vezaynk Apr 27, 2023
e1e88ab
apply fix
vezaynk Apr 28, 2023
fce6f6e
Dev and Prod working
vezaynk Apr 28, 2023
a8fb7a8
Fix up tests
vezaynk Apr 28, 2023
aef4297
Remove Worker.js
vezaynk Apr 29, 2023
8892002
Streaming works
vezaynk May 4, 2023
34e6535
Setup worker pool
vezaynk May 5, 2023
d305a74
Setup preloading
vezaynk May 5, 2023
c9b919b
Add transform support
vezaynk May 5, 2023
19002c7
Cleanup 1
vezaynk May 5, 2023
20df079
One more ignore
vezaynk May 5, 2023
9598aa8
bump dev dependencies
vezaynk May 8, 2023
d1f4dd1
Use `satisfies` on postMessage
vezaynk May 8, 2023
108bafc
Building works
vezaynk May 16, 2023
4a6f97b
Forward more types into pass-through
vezaynk May 16, 2023
f9b6aa5
Try-catch load ts-node
vezaynk May 16, 2023
8e8065e
Add comment
vezaynk May 16, 2023
0c95835
Set up transform hook test
vezaynk May 16, 2023
a82434f
Merge branch 'main' of https://github.com/gadget-inc/fastify-renderer
vezaynk Nov 2, 2023
2180e04
Things are cooking, but not working
vezaynk Nov 3, 2023
879f579
It's alive!
vezaynk Nov 3, 2023
a5fab24
lint
vezaynk Nov 3, 2023
94a23bc
Merge branch 'work-on-working'
vezaynk Nov 3, 2023
7d0e154
some cleanup
vezaynk Nov 3, 2023
4f67ad1
Some test cleanup
vezaynk Nov 3, 2023
ff8043e
Improving semantics
vezaynk Nov 3, 2023
0a99ad3
nonce WIP
vezaynk Nov 4, 2023
eee3c2b
Nonces work
vezaynk Nov 4, 2023
4951bba
Trying to fix tests
vezaynk Nov 4, 2023
fd33bae
Disable a bunch of tests
vezaynk Nov 4, 2023
0118f1b
version bumpings
vezaynk Nov 4, 2023
978cf5a
Fixing ts issues
vezaynk Nov 4, 2023
271765d
mo' version bumps, mo' problems
vezaynk Nov 4, 2023
0b26823
Merge branch 'main' of github.com:gadget-inc/fastify-renderer
vezaynk Nov 4, 2023
94bf9dc
More cleanup
vezaynk Nov 4, 2023
535c89b
remove settings
vezaynk Nov 4, 2023
866dd60
partially disable tests
vezaynk Nov 4, 2023
50af9e1
lint
vezaynk Nov 4, 2023
44b191c
pass root tests
vezaynk Nov 18, 2023
7a6a0ba
handle error
vezaynk Nov 18, 2023
7d9bc42
add some error handling
vezaynk Nov 18, 2023
e38fcc7
Upgrade to React 18
vezaynk Nov 18, 2023
e705dc0
fix deprecation warning
vezaynk Nov 18, 2023
aec6e19
add error stream
vezaynk Nov 18, 2023
e57a48e
fix useTransition
vezaynk Nov 18, 2023
858b98f
Demo React 18 Upgrade Errors
vezaynk Nov 19, 2023
3dd81d5
Jest to Vitest migration
vezaynk Nov 19, 2023
8de744d
Merge branch 'upgrade-react'
vezaynk Nov 19, 2023
1eb6484
All tests go
vezaynk Nov 19, 2023
8970f50
unskip test
vezaynk Nov 19, 2023
d61fc28
Add a couple tests
vezaynk Nov 19, 2023
c7a9585
improve consistency between dev and prod
vezaynk Nov 19, 2023
d89ac3b
Add defineRenderHook
vezaynk Nov 19, 2023
a20e882
remove error hook from server
vezaynk Nov 19, 2023
9eca2bc
Write test error hook
vezaynk Nov 19, 2023
6367fc7
fix comment
vezaynk Nov 19, 2023
7b160ee
remove excessive itmeout
vezaynk Nov 19, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ You can optionally provide configuration options to the plugin:
- `heads` - Function that will return html tags to be appended to the document head tag
- `tails` - Function that will return html tags to be appended to the document body tag
- `transform` - Function that will be run to transform the root react element
- `postRenderHeads` - Function (called after render) that will return html tags to be appended to the document head tag. Useful when injecting styles that rely on rendering first.
- `postRenderHeads` - Function (called after render) that will return html tags to be appended to the document head tag. Useful when injecting styles that rely on rendering first. (Not available in streaming mode)

The plugin will render the component server side and return it, where as the route handler will return the props to the frontend when needed.

Expand Down
16 changes: 7 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
"release": "pnpm -F=fastify-renderer publish",
"preinstall": "npx only-allow pnpm",
"prerelease": "pnpm -F=fastify-renderer run gitpkg publish",
"test": "jest --forceExit -w=1",
"test:debug": "cross-env FR_DEBUG_SERVE=1 node --inspect-brk ./node_modules/.bin/jest --forceExit"
"test": "vitest --no-threads"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -44,20 +43,19 @@
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"expect-playwright": "^0.8.0",
"fs-extra": "^11.1.0",
"jest": "^29.7.0",
"vitest": "^0.34.6",
"playwright-chromium": "^1.39.0",
"prettier": "^2.8.8",
"prettier-plugin-organize-imports": "^3.2.3",
"wds": "^0.18.1"
},
"pnpm": {
"overrides": {
"react": "0.0.0-experimental-4ead6b530",
"react-dom": "0.0.0-experimental-4ead6b530",
"@types/react": "17.0.4",
"@types/react-dom": "17.0.4"
"react": "^18.2.0",
"react-dom": "^18.2.0",
"@types/react": "^18.2.0",
"@types/react-dom": "^18.2.0"
}
}
}
}
196 changes: 0 additions & 196 deletions packages/fastify-renderer/jest.config.js

This file was deleted.

25 changes: 12 additions & 13 deletions packages/fastify-renderer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"lint:fix": "prettier --loglevel warn --write \"{src,test}/**/*.{ts,tsx}\" && eslint \"{src,test}/**/*.{ts,tsx}\" --quiet --fix",
"prepublishOnly": "npm run build",
"test": "run-s build test:unit lint",
"test:unit": "jest"
"test:unit": "vitest"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -66,35 +66,34 @@
"http-errors": "^1.8.1",
"middie": "^5.4.0",
"path-to-regexp": "^6.2.1",
"resource-pooler": "^0.2.0",
"sanitize-filename": "^1.6.3",
"stream-template": "^0.0.10",
"vite": "^2.9.15",
"wouter": "^2.7.5"
},
"peerDependencies": {
"fastify": "^3.13.0",
"react": "experimental",
"react-dom": "experimental"
"react": "*",
"react-dom": "*"
},
"devDependencies": {
"@swc/core": "^1.3.95",
"@swc/jest": "^0.2.29",
"@types/connect": "^3.4.35",
"@types/jest": "^29.5.6",
"@types/node": "^18.11.9",
"@types/react": "^17.0.43",
"@types/react-dom": "^17.0.11",
"@types/react": "^18.2.0",
"@types/react-dom": "^18.2.0",
"@types/sanitize-filename": "^1.6.3",
"@typescript-eslint/eslint-plugin": "^5.40.0",
"@typescript-eslint/parser": "^5.40.0",
"@typescript-eslint/eslint-plugin": "^5.59.2",
"@typescript-eslint/parser": "^5.59.2",
"cheerio": "^1.0.0-rc.12",
"fastify": "^3.29.0",
"gitpkg": "^1.0.0-beta.2",
"jest": "^29.7.0",
"vitest": "^0.34.6",
"npm-run-all": "^4.1.5",
"pino-pretty": "^4.8.0",
"react": "0.0.0-experimental-4ead6b530",
"react-dom": "0.0.0-experimental-4ead6b530",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"rimraf": "^3.0.2",
"typescript": "^5.2.2"
},
Expand All @@ -104,4 +103,4 @@
"README.md",
"LICENSE"
]
}
}
2 changes: 1 addition & 1 deletion packages/fastify-renderer/src/client/react/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { createContext } from 'react'
export { Link, Redirect, Route, Router, Switch, useLocation, useRoute, useRouter } from 'wouter'
export { useNavigationDetails, useTransitionLocation } from './locationHook'
export { Root } from './Root'
export type { LayoutProps } from './Root'
export { useNavigationDetails, useTransitionLocation } from './locationHook'

export const RenderBusContext = createContext<any>(null as any)

Expand Down
4 changes: 2 additions & 2 deletions packages/fastify-renderer/src/client/react/locationHook.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { unstable_useTransition as useTransition, useCallback, useEffect, useRef, useState } from 'react'
import { useTransition, useCallback, useEffect, useRef, useState } from 'react'
import { NavigationHistory, useLocation, useRouter } from 'wouter'

/**
Expand All @@ -19,7 +19,7 @@ export const events = [eventPopstate, eventPushState, eventReplaceState]
export const useTransitionLocation = ({ base = '' } = {}) => {
const [path, update] = useState(() => currentPathname(base)) // @see https://reactjs.org/docs/hooks-reference.html#lazy-initial-state
const prevLocation = useRef(path + location.search + location.hash)
const [startTransition, isPending] = useTransition()
const [isPending, startTransition] = useTransition()
const router = useRouter()
useEffect(() => {
if (!router.navigationHistory)
Expand Down
12 changes: 9 additions & 3 deletions packages/fastify-renderer/src/client/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
"compilerOptions": {
"outDir": "../../client",
"module": "esnext",
"types": ["react/experimental", "react-dom/experimental"],
"lib": ["ESNext", "DOM"]
"types": [
"react/experimental",
"react-dom/experimental"
],
"lib": [
"ESNext",
"DOM"
]
}
}
}
Loading