-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add actions and semi-splittable routes to playgrounds
- Loading branch information
1 parent
4da0737
commit 2fb37e0
Showing
10 changed files
with
144 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
playground/split-route-modules-spa/app/routes/semi-splittable.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Form, useLoaderData, useActionData } from "react-router"; | ||
|
||
// Dummy variable to prevent route exports from being split | ||
let shared: null = null; | ||
|
||
export const clientLoader = async () => { | ||
await new Promise((resolve) => setTimeout(resolve, 1000)); | ||
return shared ?? "Hello from unsplittable client loader"; | ||
}; | ||
|
||
export const clientAction = async () => { | ||
await new Promise((resolve) => setTimeout(resolve, 1000)); | ||
return "Hello from splittable client action"; | ||
}; | ||
|
||
export default function Hello() { | ||
const message = useLoaderData() as Awaited<ReturnType<typeof clientLoader>>; | ||
const actionData = useActionData() as Awaited< | ||
ReturnType<typeof clientAction> | ||
>; | ||
return ( | ||
<> | ||
<p>{message}</p> | ||
<p>{actionData}</p> | ||
<Form method="post"> | ||
<button>Submit</button> | ||
</Form> | ||
</> | ||
); | ||
} |
22 changes: 17 additions & 5 deletions
22
playground/split-route-modules-spa/app/routes/splittable.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,27 @@ | ||
import { useLoaderData } from "react-router"; | ||
import { Form, useLoaderData, useActionData } from "react-router"; | ||
|
||
export const clientLoader = async () => { | ||
await new Promise((resolve) => setTimeout(resolve, 1000)); | ||
return "Hello from splittable client loader"; | ||
}; | ||
|
||
// Uncomment the following line to see an error message since HydrateFallback is | ||
// not a valid export outside of the root route in SPA mode: | ||
// export function HydrateFallback() {} | ||
export const clientAction = async () => { | ||
await new Promise((resolve) => setTimeout(resolve, 1000)); | ||
return "Hello from splittable client action"; | ||
}; | ||
|
||
export default function Hello() { | ||
const message = useLoaderData() as Awaited<ReturnType<typeof clientLoader>>; | ||
return <div>{message}</div>; | ||
const actionData = useActionData() as Awaited< | ||
ReturnType<typeof clientAction> | ||
>; | ||
return ( | ||
<> | ||
<p>{message}</p> | ||
<p>{actionData}</p> | ||
<Form method="post"> | ||
<button>Submit</button> | ||
</Form> | ||
</> | ||
); | ||
} |
22 changes: 19 additions & 3 deletions
22
playground/split-route-modules-spa/app/routes/unsplittable.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,30 @@ | ||
import { useLoaderData } from "react-router"; | ||
import { Form, useLoaderData, useActionData } from "react-router"; | ||
|
||
// Dummy variable to prevent route exports from being split | ||
let shared: null = null; | ||
|
||
export const clientLoader = async () => { | ||
await new Promise((resolve) => setTimeout(resolve, 1000)); | ||
return shared ?? "Hello from splittable client loader"; | ||
return shared ?? "Hello from unsplittable client loader"; | ||
}; | ||
|
||
export const clientAction = async () => { | ||
await new Promise((resolve) => setTimeout(resolve, 1000)); | ||
return shared ?? "Hello from unsplittable client action"; | ||
}; | ||
|
||
export default function Hello() { | ||
const message = useLoaderData() as Awaited<ReturnType<typeof clientLoader>>; | ||
return shared ?? <div>{message}</div>; | ||
const actionData = useActionData() as Awaited< | ||
ReturnType<typeof clientAction> | ||
>; | ||
return ( | ||
<> | ||
<p>{message}</p> | ||
<p>{actionData}</p> | ||
<Form method="post"> | ||
<button>Submit</button> | ||
</Form> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
playground/split-route-modules/app/routes/semi-splittable.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Form, useLoaderData, useActionData } from "react-router"; | ||
|
||
// Dummy variable to prevent route exports from being split | ||
let shared: null = null; | ||
|
||
export const clientLoader = async () => { | ||
await new Promise((resolve) => setTimeout(resolve, 1000)); | ||
return shared ?? "Hello from unsplittable client loader"; | ||
}; | ||
|
||
export const clientAction = async () => { | ||
await new Promise((resolve) => setTimeout(resolve, 1000)); | ||
return "Hello from splittable client action"; | ||
}; | ||
|
||
export function HydrateFallback() { | ||
return shared ?? <div>Loading...</div>; | ||
} | ||
|
||
export default function Hello() { | ||
const message = useLoaderData() as Awaited<ReturnType<typeof clientLoader>>; | ||
const actionData = useActionData() as Awaited< | ||
ReturnType<typeof clientAction> | ||
>; | ||
return ( | ||
<> | ||
<p>{message}</p> | ||
<p>{actionData}</p> | ||
<Form method="post"> | ||
<button>Submit</button> | ||
</Form> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,31 @@ | ||
import { useLoaderData } from "react-router"; | ||
import { Form, useLoaderData, useActionData } from "react-router"; | ||
|
||
export const clientLoader = async () => { | ||
await new Promise((resolve) => setTimeout(resolve, 1000)); | ||
return "Hello from splittable client loader"; | ||
}; | ||
|
||
export const clientAction = async () => { | ||
await new Promise((resolve) => setTimeout(resolve, 1000)); | ||
return "Hello from splittable client action"; | ||
}; | ||
|
||
export function HydrateFallback() { | ||
return <div>Loading...</div>; | ||
} | ||
|
||
export default function Hello() { | ||
const message = useLoaderData() as Awaited<ReturnType<typeof clientLoader>>; | ||
return <div>{message}</div>; | ||
const actionData = useActionData() as Awaited< | ||
ReturnType<typeof clientAction> | ||
>; | ||
return ( | ||
<> | ||
<p>{message}</p> | ||
<p>{actionData}</p> | ||
<Form method="post"> | ||
<button>Submit</button> | ||
</Form> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters