frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

When 'perfect' code fails

https://marma.dev/articles/2025/when-perfect-code-fails
26•vinhnx•8h ago

Comments

sim7c00•1d ago
always nice to read about these things. i like the note on 'all tests were green'. it sounds like the test of this function only test for the good case right? it should also test a false case? or am i missing something here?
marekzan•15h ago
We tested for both, the "happy" and the negative path. But the Javascript unit tests are run without the framework in between. So our function was returning expected results when run in isolation. Only when running it with Next.js the function became async which led to this dilemma.
copypaper•1d ago
I think you're looking for `import 'server-only'` and not "use server";. Use server exposes functions as endpoints to the client. I.e. they are simply obfuscated api endpoints without boilerplate. Their main use is for mutations such as a form submission from the client.

Since pages are, by default, SSR, you don't need to have the server call out to itself to run an endpoint to check permissions. Instead, the server should just run the function.

I'm pretty sure Next does some behind the scenes black magic optimizations and doesn't actually make an API request over the wire, but it's still running through some layer of abstractions (causing it to be async) to run the function when instead it could simply be a synchronous function if implemented properly.

These abstractions make sense if you know how to use them properly, but I honestly blame Nextjs for the whole server action confusion. I remember when they first came out and seeing how almost every single question on /r/nextjs was about being confused about server actions. All these footguns and confusion to avoid some boilerplate... I'm not sure if they've improved it since, but I've moved to Svelte and haven't looked back.

marekzan•15h ago
Yes you are right and after our learning we changed the code to not use `use server` anymore for this kind of operations.

The documentation and tooling definitely got better and I don't think that such a situation is possible with the latest versions.

I just hope that some people who are still running the specific Next.js version won't fall into this as we did.

gpvos•17m ago
SSR = Server-side rendered
mzajc•2h ago
> The snippet above was called as a server function. This is React's new way of calling server side code from the client side.

Tangential to the post, but mixing client-side and server-side code sounds like a recipe for disaster. There are already one too many services that perform authorization client-side, and I have a feeling making it harder to tell what runs where only makes the situation worse.

mexicocitinluez•1h ago
Doesn't the 'use client'/'use server' directives tell you this?
Joel_Mckay•2h ago
"The Power of 10 Rules" (2006, Gerard J. Holzmann)

https://en.wikipedia.org/wiki/The_Power_of_10:_Rules_for_Dev...

Generally wise advice. =3

sholladay•1h ago
This is why you should:

- Write functional tests, not unit tests

- Not use compilers or other systems that do a lot of black magic (like changing the type signature of your functions (!))

p1necone•43m ago
I almost never write single function unit tests. There's usually some subset of the codebase that's self contained that makes sense to be the "unit" you're testing, but it's almost always a handful of functions with a clear entry point.

My general rule is to never mock or remove anything that has no side effects from the execution path of a test, even if it's some utility function that's already tested in isolation in its own test suite - trying to isolate every little bit of behaviour to be tested separately is just a bunch of extra work for questionable benefit.

I still call these tests "unit tests", and I think a lot of people do also. But there are the dogmatic people to whom only a test covering a single function with all dependencies mocked out is a true unit test.

actionfromafar•42m ago
Use languages with truthy / falsey values.
throw-the-towel•1h ago
> When we called the isOwner function, it returned a Promise even though our function signature did not specify it as an async function. Our synchronous-looking function was invisibly converted into an async function. This meant it no longer returned a boolean, it returned a Promise.

Oh God.

mexicocitinluez•1h ago
My jaw dropped.
rileymat2•1h ago
I don't know next.js, can someone explain how the client side can call a server function inside of an IF on the client side for security? It seems like there would be a trivial bypass of the security from the client side.
chrysoprace•48m ago
It opaquely makes a network call. You call it from the client-side and it abstracts away the network round-trip, but inside the function context you're running code on the server.

Under the hood it opens up an endpoint and the function calls it via a HTTP request.

grebc•32m ago
My first thought was is JavaScript === case insensitive for string comps, because while I do use minimal JavaScript to enhance some web pages functionality it’s all basic vanilla JS.

But the answer is actually batshit crazy.

pif•19m ago
And still there are coders who prefer non-statically typed languages, tsk tsk...
tantalor•16m ago
Explain how static typing would avoid this problem.
jongjong•18m ago
IMO, the idea of trying to blur the line between client and server is a big mistake. I worked on WebSocket frameworks in the Node.js space so I was also tempted but I completely abandoned this approach years ago. Though with Node.js, I do often reuse utility functions between client and server, I reject any framework which tries to hide the separation. I demand to have complete understanding of where the code is executing and how. I need to know what is being executed, where and how.

I also avoid technologies where the code I write is different from the code being executed. This is why I've been avoiding TypeScript. It performs code transformations which obfuscate my understanding of the logic which will be executed. With TS, the code I write is not the code which gets executed. This is scary to me. My code gets compiled into some messy junk-looking code and then that messy junk gets executed in ways I don't fully comprehend.

dragonwriter•9m ago
> It is written as if this only applies to functions you mark with use server and not the whole file.

The demonstration code illustrating the problem uses a file-level "use server" directive (and doesn't have other functions in the same file with the problem isOwner function); if they were using function level "use server" directives and it impacted a different function in the same file, I would say this is clearly surprising and unexpected (and even buggy) behavior, but this seems to be using a clearly documented feature and getting exactly what is advertised.

Easy RISC-V

https://dramforever.github.io/easyriscv/
98•todsacerdoti•2h ago•10 comments

Claude for Excel

https://www.claude.com/claude-for-excel
389•meetpateltech•7h ago•299 comments

JetKVM – Control any computer remotely

https://jetkvm.com/
233•elashri•6h ago•130 comments

10M people watched a YouTuber shim a lock; the lock company sued him – bad idea

https://arstechnica.com/tech-policy/2025/10/suing-a-popular-youtuber-who-shimmed-a-130-lock-what-...
616•Brajeshwar•10h ago•250 comments

Simplify Your Code: Functional Core, Imperative Shell

https://testing.googleblog.com/2025/10/simplify-your-code-functional-core.html
114•reqo•2d ago•44 comments

Pyrex catalog from from 1938 with hand-drawn lab glassware [pdf]

https://exhibitdb.cmog.org/opacimages/Images/Pyrex/Rakow_1000132877.pdf
240•speckx•8h ago•58 comments

Go beyond Goroutines: introducing the Reactive paradigm

https://samuelberthe.substack.com/p/go-beyond-goroutines-introducing
22•samber•1w ago•12 comments

The new calculus of AI-based coding

https://blog.joemag.dev/2025/10/the-new-calculus-of-ai-based-coding.html
56•todsacerdoti•5h ago•36 comments

Why Busy Beaver hunters fear the Antihydra

https://benbrubaker.com/why-busy-beaver-hunters-fear-the-antihydra/
117•Bogdanp•6h ago•32 comments

MCP-Scanner – Scan MCP Servers for vulnerabilities

https://github.com/cisco-ai-defense/mcp-scanner
89•hsanthan•5h ago•27 comments

Rust cross-platform GPUI components

https://github.com/longbridge/gpui-component
442•xvilka•13h ago•186 comments

Tags to make HTML work like you expect

https://blog.jim-nielsen.com/2025/dont-forget-these-html-tags/
374•FromTheArchives•13h ago•199 comments

TOON – Token Oriented Object Notation

https://github.com/johannschopplich/toon
56•royosherove•1d ago•23 comments

Avoid 2:00 and 3:00 am cron jobs (2013)

https://www.endpointdev.com/blog/2013/04/avoid-200-and-300-am-cron-jobs/
231•pera•6h ago•220 comments

Solving regex crosswords with Z3

https://blog.nelhage.com/post/regex-crosswords-z3/
39•atilimcetin•6d ago•0 comments

Image Dithering: Eleven Algorithms and Source Code (2012)

https://tannerhelland.com/2012/12/28/dithering-eleven-algorithms-source-code.html
34•Bogdanp•3d ago•8 comments

When 'perfect' code fails

https://marma.dev/articles/2025/when-perfect-code-fails
26•vinhnx•8h ago•20 comments

Sieve (YC X25) is hiring engineers to build video datasets for frontier AI

https://www.sievedata.com/
1•mvoodarla•6h ago

Study finds growing social circles may fuel polarization

https://phys.org/news/2025-10-friends-division-social-circles-fuel.html
75•geox•4h ago•74 comments

It's not always DNS

https://notes.pault.ag/its-not-always-dns/
24•todsacerdoti•5h ago•15 comments

Show HN: Dlog – Journaling and AI coach that learns what drives well-being (Mac)

https://dlog.pro/
12•dr-j•5h ago•5 comments

Iroh-blobs 0.95 – New features – Iroh

https://www.iroh.computer/blog/iroh-blobs-0-95-new-features
4•janandonly•6d ago•0 comments

The last European train that travels by sea

https://www.bbc.com/travel/article/20251024-the-last-european-train-that-travels-by-sea
128•1659447091•14h ago•122 comments

Should LLMs just treat text content as an image?

https://www.seangoedecke.com/text-tokens-as-image-tokens/
131•ingve•6d ago•80 comments

PSF has withdrawn $1.5M proposal to US Government grant program

https://pyfound.blogspot.com/2025/10/NSF-funding-statement.html
403•lumpa•8h ago•334 comments

Show HN: Erdos – open-source, AI data science IDE

https://www.lotas.ai/erdos
41•jorgeoguerra•7h ago•21 comments

fnox, a secret manager that pairs well with mise

https://github.com/jdx/mise/discussions/6779
101•bpierre•6h ago•22 comments

Eight Million Copies of Moby-Dick (2014)

https://thevoltablog.wordpress.com/2014/01/27/nicolas-mugaveros-eight-million-copies-of-moby-dick...
29•awalias•4d ago•10 comments

Why Nigeria accepted GMOs

https://www.asimov.press/p/nigeria-crops
37•surprisetalk•5h ago•71 comments

Let the little guys in: A context sharing runtime for the personalised web

https://arjun.md/little-guys
55•louisbarclay•5h ago•11 comments