Next.js

Next.js: Turbopack Gets Smarter & Tests Get More Reliable

Today's episode covers six merged PRs focused on making Turbopack's module resolution smarter and the test suite more reliable. The standout change fixes a critical bug in how Turbopack handles platform-specific file extensions, while new hash-based change detection makes builds more efficient. Plus, several test timeout fixes should reduce those frustrating flaky test failures.

Duration: PT4M6S

https://podlog.io/listen/next-js-36fde2ae/episode/next-js-turbopack-gets-smarter-tests-get-more-reliable-468dc103

Transcript

Hey there, fellow developers! Welcome back to another episode of the Next.js podcast. I'm your host, and I'm genuinely excited to dive into what's been happening in the Next.js codebase. Grab your favorite beverage because we've got some really solid improvements to talk about today.

So here's what caught my attention - we had six pull requests merge yesterday, and they tell a really interesting story about both making Turbopack smarter and making our development experience more reliable. Let me walk you through the highlights.

First up, and this is a big one - Tobias fixed a sneaky bug in Turbopack's module resolution that was causing headaches for anyone using platform-specific files. You know those `.web.tsx` and `.native.tsx` files that are super common in React Native and Expo projects? Well, Turbopack was supposed to respect the order you specified in your `resolveExtensions` config, but it wasn't always doing that.

Here's what was happening - when you had both `Component.web.tsx` and `Component.tsx` in your project, and you told Next.js "hey, prioritize the web version first," Turbopack would sometimes still pick the default version instead. The fix was actually just a one-line change in the Rust code, replacing a hardcoded zero with the proper index variable. Sometimes the biggest bugs have the simplest fixes, right?

But what I love about this PR is how thoroughly it was tested. They added both Turbopack-specific unit tests and end-to-end tests in Next.js to make sure this behavior works correctly going forward. That's the kind of attention to detail that gives me confidence in the framework.

The second major change is this really clever optimization around something called "hash-based change detection." Now, this might sound super technical, but bear with me because it's actually pretty cool. Basically, when Turbopack is figuring out whether something has changed and needs to be rebuilt, it can now store a hash of the data instead of keeping the full data around. This means less memory usage and smarter invalidation - it won't unnecessarily rebuild things that haven't actually changed, even if the original data got cleared from memory.

There's also a nice API cleanup where they removed an old method called `Vc::resolve()` and migrated everything to use `Vc::to_resolved()` instead. The new method has better type safety, which means fewer opportunities for bugs to slip through. It's one of those behind-the-scenes improvements that makes the codebase more maintainable.

Now, here's something that'll make your day better - they fixed a bunch of flaky tests. You know those tests that sometimes pass and sometimes fail for no apparent reason? Super frustrating when you're trying to contribute to Next.js or when you're running your own test suite and wondering if your code is broken or if it's just a timing issue.

The team identified that some tests were timing out because navigating between the App Router and Pages Router triggers a full page reload, and in development mode, that first compilation can take longer than expected. So they bumped the timeout from 10 seconds to 30 seconds for these specific scenarios. It's one of those fixes that seems small but will save developers hours of debugging time.

They also fixed some issues with typed routes tests where the test was trying to run before the route types were fully generated. Again, it's about getting the timing right and making sure the development experience is smooth.

What I really appreciate about today's batch of changes is how they show the team's commitment to both performance and reliability. The Turbopack improvements make builds faster and more predictable, while the test fixes make contributing to Next.js itself a better experience.

So here's today's focus for you - if you're working with platform-specific files in your React Native Web or Expo projects, this Turbopack fix should make your imports much more reliable. And if you've been holding off on trying out Turbopack because of edge cases like this, maybe it's time to give it another shot.

Keep building amazing things, and I'll catch you in the next episode where we'll see what new improvements land in the Next.js ecosystem. Until then, happy coding!