Inertia Link

@inertiajs/inertia 0.10.0 and Laravel Jetstream: update the Head and Link component usage

Published July 23rd, 2021

With two time consuming projects wrapped up this week, I finally had time to come back to my internal InertiaJS project – so thought I’d update all the underlying libraries, from Laravel to Tailwind CSS.

Update, compile, and then, uh oh, links aren’t working. What gives?

Looking at the console, I was presented with an incredibly informative message:

[Vue warn]: Failed to resolve component: inertia-link
at <Login ... >
    at <Inertia ... >
    at <App>

There’s actually no sarcasm there. That is a superb message to see. Sure, links are broken but not only does this tell me what the issue is, but a drop-dead simple trace as to where in the app it is.

Going to the Login component, which was generated from a Laravel Jetstream stub (side note, Laravel Jetstream is flipping awesome at getting up and running with a new app), I can see that <inertia-link> is most definitely being used.

I’ll admit I have been out of the Inertia world for a few months due to other projects, but checking out the release notes showed the recent 0.10.0 release included a pull request from Jonathan Reinink (Inertia’s creator) that removed the global components for Head and Link.

The <inertia-head> is a more recent addition, coming in 0.9.1, to allow for updating of head content (check out my getting started with <inertia-head> post for more), and <inertia-link> is pretty self-explanatory. You know, a link, that's for Inertia. 

Rather than be included globally by default, the Head and Link components should now be included as required in other components. This change was introduced based on:

  1. improved tree shaking, and

  2. ability to improve code maintainability and IDE assistance

Take a look at the link in the pull request for a discussion on twitter about this approach.

So pre-0.10.0, your links use the <inertia-link> component that is globally available. 

<inertia-link ...>
  I'm an old link
</inertia-link>

From 0.10.0, you need to explicitly import the <Link> component from the inertia-vue3 library, and change <inertia-link> to <Link>. That's it:

<template>
    <div>
        ...
        <Link ...>
            I'm a new link
        </Link>
        ...
    </div>
</template>
<script>
import {Link} from '@inertiajs/inertia-vue3';

export default {
    components: {
        Link
    }
}
</script>

If your app is still young (like mine was), it was only a change that needed to be made in a few places: but for larger apps it may be a little more time consuming.

But hey, stepping forward with best practice is always worth the time.

A fix is coming for new Jetstream installations soon (already resolved on Github), but if you’re updating an older Jetstream install with the new InertiaJS, you’ll need to either globally add Head and Link, or update each Page to include these components.

You may be interested in...