Skip to content

Commit

Permalink
[1.x] Inertia v1 (#238)
Browse files Browse the repository at this point in the history
* Update dependencies

* Rename imports

* Update progress usage

* Update setup arguments

* Remove `.value` from Vue usePage()

* Update Vite `ssr.noExternal` setting

* Update to Inertia 1.0

* Update Inertia Laravel package

* Remove creation of Inertia config on SSR install

This is no longer required as Inertia will automatically detect SSR.

* Remove `ssr.noExternal` from Vite config

This doesn't seem to be required any longer.

* Remove unused import

* Pass empty object to `useForm`
  • Loading branch information
jessarcher authored Jan 17, 2023
1 parent dd3134b commit 4280282
Show file tree
Hide file tree
Showing 39 changed files with 56 additions and 86 deletions.
36 changes: 3 additions & 33 deletions src/Console/InstallsInertiaStacks.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Illuminate\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Process\Process;

trait InstallsInertiaStacks
{
Expand All @@ -16,16 +15,14 @@ trait InstallsInertiaStacks
protected function installInertiaVueStack()
{
// Install Inertia...
if (! $this->requireComposerPackages('inertiajs/inertia-laravel:^0.6.3', 'laravel/sanctum:^3.2', 'tightenco/ziggy:^1.0')) {
if (! $this->requireComposerPackages('inertiajs/inertia-laravel:^0.6.8', 'laravel/sanctum:^3.2', 'tightenco/ziggy:^1.0')) {
return 1;
}

// NPM Packages...
$this->updateNodePackages(function ($packages) {
return [
'@inertiajs/inertia' => '^0.11.0',
'@inertiajs/inertia-vue3' => '^0.6.0',
'@inertiajs/progress' => '^0.2.7',
'@inertiajs/vue3' => '^1.0.0',
'@tailwindcss/forms' => '^0.5.3',
'@vitejs/plugin-vue' => '^4.0.0',
'autoprefixer' => '^10.4.12',
Expand Down Expand Up @@ -115,22 +112,12 @@ protected function installInertiaVueSsrStack()
{
$this->updateNodePackages(function ($packages) {
return [
'@inertiajs/server' => '^0.1.0',
'@vue/server-renderer' => '^3.2.31',
] + $packages;
});

copy(__DIR__.'/../../stubs/inertia-vue/resources/js/ssr.js', resource_path('js/ssr.js'));
$this->replaceInFile("input: 'resources/js/app.js',", "input: 'resources/js/app.js',".PHP_EOL." ssr: 'resources/js/ssr.js',", base_path('vite.config.js'));
$this->replaceInFile('});', ' ssr: {'.PHP_EOL." noExternal: ['@inertiajs/server'],".PHP_EOL.' },'.PHP_EOL.'});', base_path('vite.config.js'));

(new Process([$this->phpBinary(), 'artisan', 'vendor:publish', '--provider=Inertia\ServiceProvider', '--force'], base_path()))
->setTimeout(null)
->run(function ($type, $output) {
$this->output->write($output);
});

$this->replaceInFile("'enabled' => false", "'enabled' => true", config_path('inertia.php'));
$this->replaceInFile('vite build', 'vite build && vite build --ssr', base_path('package.json'));
$this->replaceInFile('/node_modules', '/bootstrap/ssr'.PHP_EOL.'/node_modules', base_path('.gitignore'));
}
Expand All @@ -151,9 +138,7 @@ protected function installInertiaReactStack()
$this->updateNodePackages(function ($packages) {
return [
'@headlessui/react' => '^1.4.2',
'@inertiajs/inertia' => '^0.11.0',
'@inertiajs/inertia-react' => '^0.8.1',
'@inertiajs/progress' => '^0.2.6',
'@inertiajs/react' => '^1.0.0',
'@tailwindcss/forms' => '^0.5.3',
'@vitejs/plugin-react' => '^3.0.0',
'autoprefixer' => '^10.4.12',
Expand Down Expand Up @@ -248,23 +233,8 @@ protected function installInertiaReactStack()
*/
protected function installInertiaReactSsrStack()
{
$this->updateNodePackages(function ($packages) {
return [
'@inertiajs/server' => '^0.1.0',
] + $packages;
});

copy(__DIR__.'/../../stubs/inertia-react/resources/js/ssr.jsx', resource_path('js/ssr.jsx'));
$this->replaceInFile("input: 'resources/js/app.jsx',", "input: 'resources/js/app.jsx',".PHP_EOL." ssr: 'resources/js/ssr.jsx',", base_path('vite.config.js'));
$this->replaceInFile('});', ' ssr: {'.PHP_EOL." noExternal: ['@inertiajs/server'],".PHP_EOL.' },'.PHP_EOL.'});', base_path('vite.config.js'));

(new Process([$this->phpBinary(), 'artisan', 'vendor:publish', '--provider=Inertia\ServiceProvider', '--force'], base_path()))
->setTimeout(null)
->run(function ($type, $output) {
$this->output->write($output);
});

$this->replaceInFile("'enabled' => false", "'enabled' => true", config_path('inertia.php'));
$this->replaceInFile('vite build', 'vite build && vite build --ssr', base_path('package.json'));
$this->replaceInFile('/node_modules', '/bootstrap/ssr'.PHP_EOL.'/node_modules', base_path('.gitignore'));
}
Expand Down
2 changes: 1 addition & 1 deletion stubs/inertia-react/resources/js/Components/Dropdown.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState, createContext, useContext, Fragment } from 'react';
import { Link } from '@inertiajs/inertia-react';
import { Link } from '@inertiajs/react';
import { Transition } from '@headlessui/react';

const DropDownContext = createContext();
Expand Down
2 changes: 1 addition & 1 deletion stubs/inertia-react/resources/js/Components/NavLink.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Link } from '@inertiajs/inertia-react';
import { Link } from '@inertiajs/react';

export default function NavLink({ href, active, children }) {
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Link } from '@inertiajs/inertia-react';
import { Link } from '@inertiajs/react';

export default function ResponsiveNavLink({ method = 'get', as = 'a', href, active = false, children }) {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import ApplicationLogo from '@/Components/ApplicationLogo';
import Dropdown from '@/Components/Dropdown';
import NavLink from '@/Components/NavLink';
import ResponsiveNavLink from '@/Components/ResponsiveNavLink';
import { Link } from '@inertiajs/inertia-react';
import { Link } from '@inertiajs/react';

export default function Authenticated({ auth, header, children }) {
const [showingNavigationDropdown, setShowingNavigationDropdown] = useState(false);
Expand Down
2 changes: 1 addition & 1 deletion stubs/inertia-react/resources/js/Layouts/GuestLayout.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ApplicationLogo from '@/Components/ApplicationLogo';
import { Link } from '@inertiajs/inertia-react';
import { Link } from '@inertiajs/react';

export default function Guest({ children }) {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import InputError from '@/Components/InputError';
import InputLabel from '@/Components/InputLabel';
import PrimaryButton from '@/Components/PrimaryButton';
import TextInput from '@/Components/TextInput';
import { Head, useForm } from '@inertiajs/inertia-react';
import { Head, useForm } from '@inertiajs/react';

export default function ConfirmPassword() {
const { data, setData, post, processing, errors, reset } = useForm({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import GuestLayout from '@/Layouts/GuestLayout';
import InputError from '@/Components/InputError';
import PrimaryButton from '@/Components/PrimaryButton';
import TextInput from '@/Components/TextInput';
import { Head, useForm } from '@inertiajs/inertia-react';
import { Head, useForm } from '@inertiajs/react';

export default function ForgotPassword({ status }) {
const { data, setData, post, processing, errors } = useForm({
Expand Down
2 changes: 1 addition & 1 deletion stubs/inertia-react/resources/js/Pages/Auth/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import InputError from '@/Components/InputError';
import InputLabel from '@/Components/InputLabel';
import PrimaryButton from '@/Components/PrimaryButton';
import TextInput from '@/Components/TextInput';
import { Head, Link, useForm } from '@inertiajs/inertia-react';
import { Head, Link, useForm } from '@inertiajs/react';

export default function Login({ status, canResetPassword }) {
const { data, setData, post, processing, errors, reset } = useForm({
Expand Down
2 changes: 1 addition & 1 deletion stubs/inertia-react/resources/js/Pages/Auth/Register.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import InputError from '@/Components/InputError';
import InputLabel from '@/Components/InputLabel';
import PrimaryButton from '@/Components/PrimaryButton';
import TextInput from '@/Components/TextInput';
import { Head, Link, useForm } from '@inertiajs/inertia-react';
import { Head, Link, useForm } from '@inertiajs/react';

export default function Register() {
const { data, setData, post, processing, errors, reset } = useForm({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import InputError from '@/Components/InputError';
import InputLabel from '@/Components/InputLabel';
import PrimaryButton from '@/Components/PrimaryButton';
import TextInput from '@/Components/TextInput';
import { Head, useForm } from '@inertiajs/inertia-react';
import { Head, useForm } from '@inertiajs/react';

export default function ResetPassword({ token, email }) {
const { data, setData, post, processing, errors, reset } = useForm({
Expand Down
4 changes: 2 additions & 2 deletions stubs/inertia-react/resources/js/Pages/Auth/VerifyEmail.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import GuestLayout from '@/Layouts/GuestLayout';
import PrimaryButton from '@/Components/PrimaryButton';
import { Head, Link, useForm } from '@inertiajs/inertia-react';
import { Head, Link, useForm } from '@inertiajs/react';

export default function VerifyEmail({ status }) {
const { post, processing } = useForm();
const { post, processing } = useForm({});

const submit = (e) => {
e.preventDefault();
Expand Down
2 changes: 1 addition & 1 deletion stubs/inertia-react/resources/js/Pages/Dashboard.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout';
import { Head } from '@inertiajs/inertia-react';
import { Head } from '@inertiajs/react';

export default function Dashboard(props) {
return (
Expand Down
2 changes: 1 addition & 1 deletion stubs/inertia-react/resources/js/Pages/Profile/Edit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout';
import DeleteUserForm from './Partials/DeleteUserForm';
import UpdatePasswordForm from './Partials/UpdatePasswordForm';
import UpdateProfileInformationForm from './Partials/UpdateProfileInformationForm';
import { Head } from '@inertiajs/inertia-react';
import { Head } from '@inertiajs/react';

export default function Edit({ auth, mustVerifyEmail, status }) {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import InputLabel from '@/Components/InputLabel';
import Modal from '@/Components/Modal';
import SecondaryButton from '@/Components/SecondaryButton';
import TextInput from '@/Components/TextInput';
import { useForm } from '@inertiajs/inertia-react';
import { useForm } from '@inertiajs/react';

export default function DeleteUserForm({ className }) {
const [confirmingUserDeletion, setConfirmingUserDeletion] = useState(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import InputError from '@/Components/InputError';
import InputLabel from '@/Components/InputLabel';
import PrimaryButton from '@/Components/PrimaryButton';
import TextInput from '@/Components/TextInput';
import { useForm } from '@inertiajs/inertia-react';
import { useForm } from '@inertiajs/react';
import { Transition } from '@headlessui/react';

export default function UpdatePasswordForm({ className }) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import InputError from '@/Components/InputError';
import InputLabel from '@/Components/InputLabel';
import PrimaryButton from '@/Components/PrimaryButton';
import TextInput from '@/Components/TextInput';
import { Link, useForm, usePage } from '@inertiajs/inertia-react';
import { Link, useForm, usePage } from '@inertiajs/react';
import { Transition } from '@headlessui/react';

export default function UpdateProfileInformation({ mustVerifyEmail, status, className }) {
Expand Down
2 changes: 1 addition & 1 deletion stubs/inertia-react/resources/js/Pages/Welcome.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Link, Head } from '@inertiajs/inertia-react';
import { Link, Head } from '@inertiajs/react';

export default function Welcome(props) {
return (
Expand Down
8 changes: 4 additions & 4 deletions stubs/inertia-react/resources/js/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import './bootstrap';
import '../css/app.css';

import { createRoot } from 'react-dom/client';
import { createInertiaApp } from '@inertiajs/inertia-react';
import { InertiaProgress } from '@inertiajs/progress';
import { createInertiaApp } from '@inertiajs/react';
import { resolvePageComponent } from 'laravel-vite-plugin/inertia-helpers';

const appName = window.document.getElementsByTagName('title')[0]?.innerText || 'Laravel';
Expand All @@ -16,6 +15,7 @@ createInertiaApp({

root.render(<App {...props} />);
},
progress: {
color: '#4B5563',
},
});

InertiaProgress.init({ color: '#4B5563' });
4 changes: 2 additions & 2 deletions stubs/inertia-react/resources/js/ssr.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ReactDOMServer from 'react-dom/server';
import { createInertiaApp } from '@inertiajs/inertia-react';
import createServer from '@inertiajs/server';
import { createInertiaApp } from '@inertiajs/react';
import createServer from '@inertiajs/react/server';
import { resolvePageComponent } from 'laravel-vite-plugin/inertia-helpers';
import route from '../../vendor/tightenco/ziggy/dist/index.m';

Expand Down
2 changes: 1 addition & 1 deletion stubs/inertia-vue/resources/js/Components/DropdownLink.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup>
import { Link } from '@inertiajs/inertia-vue3';
import { Link } from '@inertiajs/vue3';
</script>

<template>
Expand Down
2 changes: 1 addition & 1 deletion stubs/inertia-vue/resources/js/Components/NavLink.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup>
import { computed } from 'vue';
import { Link } from '@inertiajs/inertia-vue3';
import { Link } from '@inertiajs/vue3';
const props = defineProps(['href', 'active']);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup>
import { computed } from 'vue';
import { Link } from '@inertiajs/inertia-vue3';
import { Link } from '@inertiajs/vue3';
const props = defineProps(['href', 'active']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Dropdown from '@/Components/Dropdown.vue';
import DropdownLink from '@/Components/DropdownLink.vue';
import NavLink from '@/Components/NavLink.vue';
import ResponsiveNavLink from '@/Components/ResponsiveNavLink.vue';
import { Link } from '@inertiajs/inertia-vue3';
import { Link } from '@inertiajs/vue3';
const showingNavigationDropdown = ref(false);
</script>
Expand Down
2 changes: 1 addition & 1 deletion stubs/inertia-vue/resources/js/Layouts/GuestLayout.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup>
import ApplicationLogo from '@/Components/ApplicationLogo.vue';
import { Link } from '@inertiajs/inertia-vue3';
import { Link } from '@inertiajs/vue3';
</script>

<template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import InputError from '@/Components/InputError.vue';
import InputLabel from '@/Components/InputLabel.vue';
import PrimaryButton from '@/Components/PrimaryButton.vue';
import TextInput from '@/Components/TextInput.vue';
import { Head, useForm } from '@inertiajs/inertia-vue3';
import { Head, useForm } from '@inertiajs/vue3';
const form = useForm({
password: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import InputError from '@/Components/InputError.vue';
import InputLabel from '@/Components/InputLabel.vue';
import PrimaryButton from '@/Components/PrimaryButton.vue';
import TextInput from '@/Components/TextInput.vue';
import { Head, useForm } from '@inertiajs/inertia-vue3';
import { Head, useForm } from '@inertiajs/vue3';
defineProps({
status: String,
Expand Down
2 changes: 1 addition & 1 deletion stubs/inertia-vue/resources/js/Pages/Auth/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import InputError from '@/Components/InputError.vue';
import InputLabel from '@/Components/InputLabel.vue';
import PrimaryButton from '@/Components/PrimaryButton.vue';
import TextInput from '@/Components/TextInput.vue';
import { Head, Link, useForm } from '@inertiajs/inertia-vue3';
import { Head, Link, useForm } from '@inertiajs/vue3';
defineProps({
canResetPassword: Boolean,
Expand Down
2 changes: 1 addition & 1 deletion stubs/inertia-vue/resources/js/Pages/Auth/Register.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import InputError from '@/Components/InputError.vue';
import InputLabel from '@/Components/InputLabel.vue';
import PrimaryButton from '@/Components/PrimaryButton.vue';
import TextInput from '@/Components/TextInput.vue';
import { Head, Link, useForm } from '@inertiajs/inertia-vue3';
import { Head, Link, useForm } from '@inertiajs/vue3';
const form = useForm({
name: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import InputError from '@/Components/InputError.vue';
import InputLabel from '@/Components/InputLabel.vue';
import PrimaryButton from '@/Components/PrimaryButton.vue';
import TextInput from '@/Components/TextInput.vue';
import { Head, useForm } from '@inertiajs/inertia-vue3';
import { Head, useForm } from '@inertiajs/vue3';
const props = defineProps({
email: String,
Expand Down
4 changes: 2 additions & 2 deletions stubs/inertia-vue/resources/js/Pages/Auth/VerifyEmail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
import { computed } from 'vue';
import GuestLayout from '@/Layouts/GuestLayout.vue';
import PrimaryButton from '@/Components/PrimaryButton.vue';
import { Head, Link, useForm } from '@inertiajs/inertia-vue3';
import { Head, Link, useForm } from '@inertiajs/vue3';
const props = defineProps({
status: String,
});
const form = useForm();
const form = useForm({});
const submit = () => {
form.post(route('verification.send'));
Expand Down
2 changes: 1 addition & 1 deletion stubs/inertia-vue/resources/js/Pages/Dashboard.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup>
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout.vue';
import { Head } from '@inertiajs/inertia-vue3';
import { Head } from '@inertiajs/vue3';
</script>

<template>
Expand Down
2 changes: 1 addition & 1 deletion stubs/inertia-vue/resources/js/Pages/Profile/Edit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout.vue';
import DeleteUserForm from './Partials/DeleteUserForm.vue';
import UpdatePasswordForm from './Partials/UpdatePasswordForm.vue';
import UpdateProfileInformationForm from './Partials/UpdateProfileInformationForm.vue';
import { Head } from '@inertiajs/inertia-vue3';
import { Head } from '@inertiajs/vue3';
defineProps({
mustVerifyEmail: Boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import InputLabel from '@/Components/InputLabel.vue';
import Modal from '@/Components/Modal.vue';
import SecondaryButton from '@/Components/SecondaryButton.vue';
import TextInput from '@/Components/TextInput.vue';
import { useForm } from '@inertiajs/inertia-vue3';
import { useForm } from '@inertiajs/vue3';
import { nextTick, ref } from 'vue';
const confirmingUserDeletion = ref(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import InputError from '@/Components/InputError.vue';
import InputLabel from '@/Components/InputLabel.vue';
import PrimaryButton from '@/Components/PrimaryButton.vue';
import TextInput from '@/Components/TextInput.vue';
import { useForm } from '@inertiajs/inertia-vue3';
import { useForm } from '@inertiajs/vue3';
import { ref } from 'vue';
const passwordInput = ref(null);
Expand Down
Loading

0 comments on commit 4280282

Please sign in to comment.