preloadNavRailLibraries function

Future<void> preloadNavRailLibraries()

Sequentially fires loadLibrary() for the seven nav-rail destinations so dart2js fetches each .part.js chunk in the background. Once each future resolves, DeferredScreen.markLoaded is called so the next mount renders synchronously without a FutureBuilder waiting frame.

On native (AOT) builds loadLibrary() is effectively a no-op — the caller in main.dart guards on kIsWeb to avoid pointless scheduling. Errors are swallowed: a failed preload just means the on-demand path will retry the load when the user actually navigates there.

Implementation

Future<void> preloadNavRailLibraries() async {
  for (final loader in navRailDeferredLoaders) {
    try {
      await loader();
      DeferredScreen.markLoaded([loader]);
    } catch (_) {
      // Best-effort. The route-level DeferredScreen will retry on demand.
    }
  }
}