Next.js Discord

Discord Forum

Good practice in fullstack

Unanswered
Kurilian Bobtail posted this in #help-forum
Open in Discord
Kurilian BobtailOP
At the moment going with Next client+server to have some shared types if needed

Remembering it to have smaller bundle and if I call a function in server is visible only there...it doesn't get in client code so should be shielded

Is there anything else besides not calling the function in client side needed to make sure my server logic is hidden?

22 Replies

Asian black bear
You can use a 'poison package' to prevent a file from ever being included in the browser bundle
@Kurilian Bobtail
Kurilian BobtailOP
Looks kinda fishy...
@Kurilian Bobtail Looks kinda fishy...
Asian black bear
It is referenced by the next.js docs directly and released by a Vercel employee.
Kurilian BobtailOP
could share doc link please?
Kurilian BobtailOP
Sorry for the reaction. Thank you for help
Asian black bear
You could also pin the version at 0.0.1 and readily inspect the three short files in the package
@Kurilian Bobtail Sorry for the reaction. Thank you for help
Asian black bear
It's ok, I was pretty suspicious of it at first too, like why not release it with next direclty
Kurilian BobtailOP
Well...not working with pages directory =))
but the docs said is quite okay with pages and bundling only based on what is called. Will probly use it in an app with new routing system
Thank you
Asian black bear
@Kurilian Bobtail It might still work if you put the server-only code in entirely separate files, but yeah it is not going to play nice with /pages stuff
Kurilian BobtailOP
Is learning project...no problem
Asian black bear
The concern over code splitting is legitimate, not just for performance, but also security/privacy
Kurilian BobtailOP
Just to make sure I got this straigth. The code splitting in nextJs is based on which page or direct code chunk is used
That package is to say...you are trying to use server js in client...like typescript with giving number to string value, right?
Asian black bear
It uses a conditional export in package.json to export a file that immediately produces an error by default, and only exports an empty JS file for react-server
  "exports": {
    ".": {
      "react-server": "./empty.js",
      "default": "./index.js"
      }
    }
Since react-server is not standard, code with that condition would only ever be emitted by a bundler that understood what it meant, and would presumably never put it in the wrong place
Kurilian BobtailOP
Ended up looking at build file and bundler analyzer. Having a better overview about code sent through pages. Thank you for help mina