-
Notifications
You must be signed in to change notification settings - Fork 970
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
POC: Avoid bundling middleware using react-server export conditions and vite plugin #10691
base: main
Are you sure you want to change the base?
Conversation
@@ -0,0 +1,9 @@ | |||
// This file is intentionally left empty, because we do not want to bundle middleware | |||
|
|||
export default function empty() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Temporary, so its easy to spot!
makeFilePath(rwPaths.web.distEntryServer) | ||
) | ||
} | ||
entryServerImport = await import(makeFilePath(rwPaths.web.distEntryServer)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Middleware router still imports from the SSR builds, not the RSC ones (which doesnt include register middleware)
const plugin = () => ({ | ||
visitor: { | ||
VariableDeclarator(path: NodePath<t.VariableDeclarator>) { | ||
// @ts-expect-error fggg |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to cleanup if we go ahead.
This is PoC (draft) - because we need to decide the direction we are going in with server routing.
Allows running OgGen middleware
This fixes running the OG Gen middleware partially i.e. it will build and run successfully, if I mock the App out like this:
It achieves this by:
1. setting the react-server export condition in the middleware
This implies that all middleware, including auth middleware, will need to have these export conditions set inorder to work under the current RSC build system.
2. Adds a plugin to remove the
registerMiddleware
function from RSC Builds(1) is not enough, Vite will still try to bundle
What doesn't work?
The OG Image middleware relies on us having access to
App
importing this in entry.server still causes build failures (due to React.context).This could be resolved in one of two ways:
a) @Tobbe mention re-introducing App back into entry server (or some form of it)
If we have another change in the way server router works, this may be resolved, but I'm unsure how to proceed right now.
b) Maybe we need to fix all the imports from App from
rwjs/auth
,rwjs/web
This will allow us to import App under server conditions without blowing up.