-
Notifications
You must be signed in to change notification settings - Fork 27.5k
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
middleware.ts treated as a client side component #54549
Comments
I think you don't need to use Is the bug still occurs if you remove the |
if you import another script marked with |
A good example where the problem arises is with AuthJS: Middleware (with sensitive information that should not be downloaded to the client) is marked as |
Anyone found a solution to this yet? |
It's kinda sad, we are about to abandon Next because of this :( In a last ditch effort, @timneutkens please can you try weigh on this issue. I don't know why it is getting so little attention - I suspect on the following is true:
|
@barryengineerapart I don't see why this issue would be a blocker for you, can you expand on that? It's just a matter of not using Middleware is not being bundled as client code / client component, |
The issue here is not only the
Branches here: You can see the diff here: mansdahlstrom1/middleware-client-component-bug@main...without-server-only |
Thanks for replying @timneutkens. Just some context: We are evaluating Next for a large company (not affiliated to this GH profile). The big problem is that middleware is tied directly to authz, which contains incredibly sensitive information. I do understand that no sensitive files will be leaked to the client by including these modules in the middleware without the The above problems implies that Next is unable to pass a security audit. I don't know the solution, but I would like Next to work, so if this is not too big of a deal, I can try get someone on our team to submit a patch. |
Can you ensure you're using the latest canary? There was a bug accessing cookies in |
thanks @ztanner. Will, try again with latest canary, when was this patched? Could you link to PR or release? Or is the patch only in canary stil? |
Was just able confirm that the |
…nts targets to be available (#55394) Users want to use `server-only` to restrict the middleware / app routes / pages api, but now it's failing as we're treating them as different webpack layers, but validating the `server-only` only with server components layers. Here we modify the rules a bit to let everyone can use "server-only" for the bundles that targeting server-side. For next-swc transformer, we introduce the new option `bundleType` which only has `"server" | "client" | "default"` 3 values: * - `server` for server-side targets, like server components, app routes, pages api, middleware * - `client` for client components targets such as client components app pages, or page routes under pages directory. * - `default` for environment like jest, we don't validate module graph with swc, replaced the `disable_checks` introduced [#54891](#54891). Refactor a bit webpack-config to adapt to the new rules, after that `server-only` will be able to used in the server-side targets conventions like middleware and `pages/api` Fixes #43700 Fixes #54549 Fixes #52833 Closes NEXT-1616 Closes NEXT-1607 Closes NEXT-1385
Verified the fix with latest canary! Thank you! |
This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Verify canary release
Provide environment information
Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 22.5.0: Thu Jun 8 22:22:20 PDT 2023; root:xnu-8796.121.3~7/RELEASE_ARM64_T6000 Binaries: Node: 16.20.0 npm: 8.19.4 Yarn: 1.22.19 pnpm: 8.4.0 Relevant Packages: next: 13.4.20-canary.6 eslint-config-next: 13.4.19 react: 18.2.0 react-dom: 18.2.0 typescript: 5.2.2 Next.js Config: output: N/A
Which area(s) of Next.js are affected? (leave empty if unsure)
Middleware / Edge (API routes, runtime)
Link to the code that reproduces this issue or a replay of the bug
https://github.com/mansdahlstrom1/middleware-client-component-bug
To Reproduce
server-only
withimport "server-only";
Describe the Bug
When using middleware we expect the middleware to run server-side only and to be able to use features like Cookies etc. But we are not able to do this as Next seem to think that the middleware is running client side.
Expected Behavior
MIddleware can be marked as server-only. Server side only features work in middleware.ts file.
OR
Clearer error message that explains the real error.
Which browser are you using? (if relevant)
116.0.5845.110
How are you deploying your application? (if relevant)
No response
NEXT-1607
The text was updated successfully, but these errors were encountered: