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

Edge getSession adds large joi-browser package #1581

Open
6 tasks done
nocodehummel opened this issue Nov 27, 2023 · 9 comments
Open
6 tasks done

Edge getSession adds large joi-browser package #1581

nocodehummel opened this issue Nov 27, 2023 · 9 comments
Labels
dependencies Pull requests that update a dependency file

Comments

@nocodehummel
Copy link

Checklist

Description

The Nextjs middleware package contains the joi-browser package when getSession is imported from @auth0/nextjs-auth0/edge. Joi-browser is deprecated and should not be part of the server bundle.

import { NextResponse } from 'next/server';
import { getSession } from '@auth0/nextjs-auth0/edge';

export async function middleware(request: Request) {
  const session = await getSession();
  return NextResponse.next();
}

It has a large impact on the Edge middleware package size.

image

Reproduction

  1. import { getSession } from '@auth0/nextjs-auth0/edge' in middleware.ts.
  2. call getSession inside the middleware function.
  3. build the application with a bundle analyzer.

Additional context

Reproduced with: https://github.com/nordicgit70/nextjs-app/tree/auth0-joi.

nextjs-auth0 version

3.3.0

Next.js version

14.0.2

Node.js version

18.18.2

@adamjmcgrath
Copy link
Contributor

Thanks for raising this @nordicgit70

Joi-browser is deprecated and should not be part of the server bundle.

Will take a look at upgrading to @hapi/[email protected]

@adamjmcgrath adamjmcgrath added the dependencies Pull requests that update a dependency file label Nov 30, 2023
@nocodehummel
Copy link
Author

Thanks, it would great if the getSession function could have less impact on the bundle size. VSC Import Cost indicates a very large import.

import { useUser } from '@auth0/nextjs-auth0/client'; 12.3k (gzipped: 2.8k)
import { getSession } from '@auth0/nextjs-auth0'; 481.9k (gzipped: 132.9k)

@nocodehummel
Copy link
Author

Closed by mistake.

@frederikprijck
Copy link
Member

frederikprijck commented Dec 18, 2023

It looks like joi-browser.min.js is pulled in from joi and is still in there, see https://github.com/hapijs/joi/blob/master/package.json#L8C6-L8C13.

When you say joi-browser, is being deprecated, I assume you refer to the npm package and not the file used in this case, is that correct? In that case, I think having joi-browser.min.js is expected and not deprecated (unless I am missing something?).

I also think we should not migrate to @hapi/joi but stay on joi, see: hapijs/joi#2411

However, we might want to consider moving away from joi altogteher, but that isn't something we can prioritise short term.

@nocodehummel
Copy link
Author

Hi, my main issue is with the impact on package size. If that could be resolved would be great. I do not have an opinion on the usage of Joi.

@nocodehummel
Copy link
Author

Hi, is it planned to resolve this?

@frederikprijck
Copy link
Member

There is currently nothing planned to move away from joi, no.

@nocodehummel
Copy link
Author

How can I reduce the package size? The package @auth0/nextjs-auth0/edge is too large to run in Edge (middleware).

@simonseddon
Copy link

Any current plans to look at this? A project I work on has recently upgraded from 1.9.2 to 3.5.0 and our bundle size has shot up. We're seeing this in our client-side bundle analyzer report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file
Projects
None yet
Development

No branches or pull requests

4 participants