Knowledge Updates

Observations while developing web applications and creating great software.

  • Middleware in React Router ↗︎

    Matt Brophy:

    We landed our initial unstable implementation of middleware behind a future flag in 7.3.0. Since then, we’ve been iterating on the API/implementation and working closely with community members who adopted the unstable flag for alpha testing. We received a ton of valuable feedback from those folks that helped us move the API to an even better spot in the end.

    We’re excited to finally stabilize these APIs in 7.9.0 behind the future.v8_middleware flag and can’t wait to see the interesting patterns folks come up with when using them. There are already a handful of useful middlewares available in remix-utils that are worth checking out!

    Providing data from a parent to a child:

    // app/root.tsx
    const context = createContext<User>();
    
    const userMiddleware: Route.MiddlewareFunction = ({ context }) => {
      let user = await getUser(request);
      context.set(userContext, user); // 👈 Provide data here
    };
    
    export const middleware = [userMiddleware];
    
    export async function loader({ context }) {
      return { user: context.get(userContext) }; // 👈 Access data here
    }
    
    // app/routes/_index.tsx
    export async function loader({ request }) {
      let user = context.get(userContext); // 👈 Access data here
      // ...
    }

    Short-circuiting child loaders with a redirect:

    // app/routes/_auth.tsx
    const requireUserMiddleware: Route.MiddlewareFunction = ({ context }) => {
      let user = await getUser(request);
      if (!user) {
        throw redirect("/login");
      }
      // ...
    };
    
    export const middleware = [requireUserMiddleware];
    
    // app/routes/_auth.profile.tsx
    export async function loader({ request }) {
      // ✅ This code will never run if there's no logged-in user
      let data = await getUserData(request);
      return data;
    }
    Via X
  • Secretive 3.0.0 ↗︎

    Secretive is an app by Max Goedjen for protecting and managing SSH keys with the Secure Enclave. I’ve been using it for years. Major release a couple days ago:

    A huge update! UI Refresh for macOS 26 Tahoe and Liquid Glass, Post-Quantum Key Support, Enhanced Security, and lots more!

  • Gall’s Law ↗︎

    A complex system that works is invariably found to have evolved from a simple system that worked. A complex system designed from scratch never works and cannot be patched up to make it work. You have to start over with a working simple system.

    John Gall, General Systemantics (1975), p. 71

  • New features available with macOS Tahoe ↗︎

    New features in Spotlight, Shortcuts, Messages, Reminders, Terminal and more. Safari’s Advanced Fingerprinting Protection. And features which work with iPhone: Phone app, Hold Assist, Live Reply, Live Activities, iPhone Apps in Spotlight, and more.

  • The Man in the Arena ↗︎

    Teddy Roosevelt’s speech in Paris, France on April 23, 1910:

    It is not the critic who counts; not the man who points out how the strong man stumbles, or where the doer of deeds could have done them better. The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood; who strives valiantly; who errs, who comes short again and again, because there is no effort without error and shortcoming; but who does actually strive to do the deeds; who knows great enthusiasms, the great devotions; who spends himself in a worthy cause; who at the best knows in the end the triumph of high achievement, and who at the worst, if he fails, at least fails while daring greatly, so that his place shall never be with those cold and timid souls who neither know victory nor defeat.

    The last few months have been full of family life and hard work. The last few days were marked by grief at the assassination of Charlie Kirk while he was in the arena. I have prioritized meeting with important people in my life to encourage them. This is a time for courage (Job 32, Revelation 21:8) and to silence evil with good works (Proverbs 14:23).

    The question must not be merely, Is there to be peace or war? The question must be, Is it right to prevail? Are the great laws of righteousness once more to be fulfilled? And the answer from a strong and virile people must be ‘Yes,’ whatever the cost.

    See you in the arena.