Skip to content

Commit 89f832b

Browse files
committed
wip
1 parent ea1d80a commit 89f832b

File tree

8 files changed

+99
-25
lines changed

8 files changed

+99
-25
lines changed

snippets/vue2-specific.jsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { useCallback, useEffect, useState } from "react";
2+
3+
export const Vue2Specific = ({ children }) => {
4+
const [code, setCode] = useState(
5+
localStorage.getItem("code").replace(/"/g, "") || null,
6+
);
7+
8+
const callback = useCallback((event) => {
9+
if (event.detail.key === "code") {
10+
setCode(event.detail.value.replace(/"/g, ""));
11+
}
12+
}, []);
13+
14+
useEffect(() => {
15+
window.addEventListener("storage", callback);
16+
window.addEventListener("localStorageUpdate", callback);
17+
18+
return () => {
19+
window.removeEventListener("storage", callback);
20+
window.removeEventListener("localStorageUpdate", callback);
21+
};
22+
});
23+
24+
if (code !== "Vue 2") {
25+
return null;
26+
}
27+
28+
return children;
29+
};

snippets/vue3-specific.jsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { useCallback, useEffect, useState } from "react";
2+
3+
export const Vue3Specific = ({ children }) => {
4+
const [code, setCode] = useState(
5+
localStorage.getItem("code").replace(/"/g, "") || null,
6+
);
7+
8+
const callback = useCallback((event) => {
9+
if (event.detail.key === "code") {
10+
setCode(event.detail.value.replace(/"/g, ""));
11+
}
12+
}, []);
13+
14+
useEffect(() => {
15+
window.addEventListener("storage", callback);
16+
window.addEventListener("localStorageUpdate", callback);
17+
18+
return () => {
19+
window.removeEventListener("storage", callback);
20+
window.removeEventListener("localStorageUpdate", callback);
21+
};
22+
});
23+
24+
if (code !== "Vue 3") {
25+
return null;
26+
}
27+
28+
return children;
29+
};

v1/advanced/server-side-rendering.mdx

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { ClientSpecific } from "/snippets/client-specific.jsx"
66
import { ReactSpecific } from "/snippets/react-specific.jsx"
77
import { SvelteSpecific } from "/snippets/svelte-specific.jsx"
88
import { VueSpecific } from "/snippets/vue-specific.jsx"
9+
import { Vue2Specific } from "/snippets/vue2-specific.jsx"
10+
import { Vue3Specific } from "/snippets/vue3-specific.jsx"
911

1012
<Warning>This is documentation for Inertia.js v1, which is no longer actively maintained. Please refer to the [v2 docs](/v2) for the latest information.</Warning>
1113

@@ -154,14 +156,14 @@ Next, we need to update our Vite configuration to build our new `ssr.js` file. W
154156

155157
```diff
156158
export default defineConfig({
157-
plugins: [
158-
laravel({
159-
input: ['resources/css/app.css', 'resources/js/app.js'],
160-
+ ssr: 'resources/js/ssr.js',
161-
refresh: true,
162-
}),
163-
// ...
164-
],
159+
plugins: [
160+
laravel({
161+
input: ['resources/css/app.css', 'resources/js/app.js'],
162+
+ ssr: 'resources/js/ssr.js',
163+
refresh: true,
164+
}),
165+
// ...
166+
],
165167
})
166168
```
167169

@@ -171,7 +173,7 @@ Next, let's update the `build` script in our `package.json` file to also build o
171173

172174
```diff
173175
"scripts": {
174-
"dev": "vite",
176+
"dev": "vite",
175177
- "build": "vite build"
176178
+ "build": "vite build && vite build --ssr"
177179
},
@@ -195,13 +197,17 @@ With the server running, you should be able to access your app within the browse
195197

196198
## Client Side Hydration
197199

200+
<ClientSpecific>
198201
Since your website is now being server-side rendered, you can instruct <VueSpecific>Vue</VueSpecific><ReactSpecific>React</ReactSpecific><SvelteSpecific>Svelte</SvelteSpecific> to "hydrate" the static markup and make it interactive instead of re-rendering all the HTML that we just generated.
202+
</ClientSpecific>
199203

200-
{/* <vue2>Inertia automatically enables client-side hydration in Vue 2 apps, so no changes are required. */}
204+
<Vue2Specific>Inertia automatically enables client-side hydration in Vue 2 apps, so no changes are required.</Vue2Specific>
201205

202-
{/* </vue2><vue3>To enable client-side hydration in a Vue 3 app, update your `app.js` file to use `createSSRApp` instead of `createApp`: */}
206+
<Vue3Specific>To enable client-side hydration in a Vue 3 app, update your `app.js` file to use `createSSRApp` instead of `createApp`:</Vue3Specific>
203207

204-
{/* </vue3><ReactSpecific>To enable client-side hydration in a React app, update your `app.js` file to use `hydrateRoot` instead of `createRoot`:</ReactSpecific><SvelteSpecific>To enable client-side hydration in a Svelte app, set the `hydratable` compiler option to `true` in your `vite.config.js` file:</SvelteSpecific> */}
208+
<ReactSpecific>To enable client-side hydration in a React app, update your `app.js` file to use `hydrateRoot` instead of `createRoot`:</ReactSpecific>
209+
210+
<SvelteSpecific>To enable client-side hydration in a Svelte app, set the `hydratable` compiler option to `true` in your `vite.config.js` file:</SvelteSpecific>
205211

206212
<CodeGroup>
207213

@@ -269,7 +275,9 @@ Since your website is now being server-side rendered, you can instruct <VueSpeci
269275

270276
</CodeGroup>
271277

272-
{/* <SvelteSpecific>You'll also need to enable hydration in your `app.js` file: */}
278+
<SvelteSpecific>
279+
280+
You'll also need to enable hydration in your `app.js` file:
273281

274282
```diff
275283
import { createInertiaApp } from '@inertiajs/svelte'
@@ -286,9 +294,13 @@ Since your website is now being server-side rendered, you can instruct <VueSpeci
286294
+ new App({ target: el, hydrate: true })
287295
+ },
288296
})
289-
```</SvelteSpecific>## Deployment
297+
```
298+
299+
</SvelteSpecific>
300+
301+
## Deployment
290302

291-
When deploying your SSR enabled app to production, you'll need to build both the client-side ( `app.js`) and server-side bundles (`ssr.js`), and then run the SSR server as a background process, typically using a process monitoring tool such as Supervisor.
303+
When deploying your SSR enabled app to production, you'll need to build both the client-side (`app.js`) and server-side bundles (`ssr.js`), and then run the SSR server as a background process, typically using a process monitoring tool such as Supervisor.
292304

293305
```bash
294306
php artisan inertia:start-ssr

v1/getting-started/upgrade-guide.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ For a complete list of all the changes, see the [release notes](https://github.c
1616

1717
## New Dependencies
1818

19-
To use previous Inertia releases, you had to install a number of libraries, including the core library ( `@inertiajs/inertia`), the adapter of your choice ( `@inertiajs/inertia-vue|vue3|react|svelte`), the progress library (`@inertiajs/progress`), and if you were using server-side rendering, the server library (`@inertiajs/server`).
19+
To use previous Inertia releases, you had to install a number of libraries, including the core library (`@inertiajs/inertia`), the adapter of your choice (`@inertiajs/inertia-vue|vue3|react|svelte`), the progress library (`@inertiajs/progress`), and if you were using server-side rendering, the server library (`@inertiajs/server`).
2020

2121
**Moving forward you are now only required to install a single library** — the adapter of your choice (Vue, React, or Svelte), and all other core libraries are automatically installed for you.
2222

v1/the-basics/pages.mdx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class UserController extends Controller
113113

114114
## Creating Layouts
115115

116-
{/* While not required, for most projects it makes sense to create a site layout that all of your pages can extend. You may have noticed in our page example above that we're wrapping the page content within a `{`<layout>`}</layout>` component. Here's an example of such a component: */}
116+
While not required, for most projects it makes sense to create a site layout that all of your pages can extend. You may have noticed in our page example above that we're wrapping the page content within a `<Layout>` component. Here's an example of such a component:
117117

118118
<CodeGroup>
119119

@@ -388,14 +388,18 @@ export default Home
388388

389389
</CodeGroup>
390390

391-
{/* <VueSpecific>If you're using Vue 2.7 or Vue 3, you can alternatively use the [defineOptions plugin](https://vue-macros.sxzz.moe/macros/define-options.html) to define a layout within `<script setup>`: */}
391+
<VueSpecific>
392+
If you're using Vue 2.7 or Vue 3, you can alternatively use the [defineOptions plugin](https://vue-macros.sxzz.moe/macros/define-options.html) to define a layout within `<script setup>`:
392393

393-
{/* ```html
394+
```html
394395
<script setup>
395396
import Layout from './Layout'
396397
defineOptions({ layout: Layout })
397398
</script>
398-
```</VueSpecific>## Default layouts */}
399+
```
400+
</VueSpecific>
401+
402+
## Default layouts
399403

400404
If you're using persistent layouts, you may find it convenient to define the default page layout in the `resolve()` callback of your application's main JavaScript file.
401405

v1/the-basics/responses.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ title: Responses
88

99
Creating an Inertia response is simple. To get started, invoke the `Inertia::render()` method within your controller or route, providing both the name of the [JavaScript page component](/v1/the-basics/pages) that you wish to render, as well as any props (data) for the page.
1010

11-
In the example below, we will pass a single prop (`event`) which contains four attributes ( `id`, `title`, `start_date` and `description`) to the `Event/Show` page component.
11+
In the example below, we will pass a single prop (`event`) which contains four attributes (`id`, `title`, `start_date` and `description`) to the `Event/Show` page component.
1212

1313
```php
1414
use Inertia\Inertia;

v2/advanced/server-side-rendering.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ You will also need to set the `hydratable` compiler option to `true` in your `vi
367367

368368
## Deployment
369369

370-
When deploying your SSR enabled app to production, you'll need to build both the client-side ( `app.js`) and server-side bundles (`ssr.js`), and then run the SSR server as a background process, typically using a process monitoring tool such as Supervisor.
370+
When deploying your SSR enabled app to production, you'll need to build both the client-side (`app.js`) and server-side bundles (`ssr.js`), and then run the SSR server as a background process, typically using a process monitoring tool such as Supervisor.
371371

372372
```bash
373373
php artisan inertia:start-ssr

v2/the-basics/responses.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ title: Responses
66

77
Creating an Inertia response is simple. To get started, invoke the `Inertia::render()` method within your controller or route, providing both the name of the [JavaScript page component](/v2/the-basics/pages) that you wish to render, as well as any properties (data) for the page.
88

9-
In the example below, we will pass a single property (`event`) which contains four attributes ( `id`, `title`, `start_date` and `description`) to the `Event/Show` page component.
9+
In the example below, we will pass a single property (`event`) which contains four attributes (`id`, `title`, `start_date` and `description`) to the `Event/Show` page component.
1010

1111
```php
1212
use Inertia\Inertia;
@@ -83,7 +83,7 @@ Arrayable objects like Eloquent models and collections are automatically convert
8383

8484
When passing props to your components, you may want to create custom classes that can transform themselves into the appropriate data format. While Laravel's `Arrayable` interface simply converts objects to arrays, Inertia offers the more powerful `ProvidesInertiaProperty` interface for context-aware transformations.
8585

86-
This interface requires a `toInertiaProperty` method that receives a `PropertyContext`object containing the property key (`$context->key`), all props for the page ( `$context->props`), and the request instance (`$context->request`).
86+
This interface requires a `toInertiaProperty` method that receives a `PropertyContext`object containing the property key (`$context->key`), all props for the page (`$context->props`), and the request instance (`$context->request`).
8787

8888
```php
8989
use Inertia\PropertyContext;
@@ -151,7 +151,7 @@ return Inertia::render('Dashboard', [
151151

152152
In some situations you may want to group related props together for reusability across different pages. You can accomplish this by implementing the `ProvidesInertiaProperties` interface.
153153

154-
This interface requires a `toInertiaProperties` method that returns an array of key-value pairs. The method receives a `RenderContext` object containing the component name ( `$context->component`) and request instance (`$context->request`).
154+
This interface requires a `toInertiaProperties` method that returns an array of key-value pairs. The method receives a `RenderContext` object containing the component name (`$context->component`) and request instance (`$context->request`).
155155

156156
```php
157157
use App\Models\User;

0 commit comments

Comments
 (0)