-
Notifications
You must be signed in to change notification settings - Fork 268
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update root files to use Layout Export (#2292)
- Loading branch information
Showing
16 changed files
with
220 additions
and
253 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
--- | ||
'skeleton': patch | ||
'@shopify/create-hydrogen': patch | ||
--- | ||
|
||
Update root to use [Remix's Layout Export pattern](https://remix.run/docs/en/main/file-conventions/root#layout-export) and eliminate the use of `useLoaderData` in root. | ||
|
||
The diff below showcase how you can make this refactor in existing application. | ||
|
||
```diff | ||
import { | ||
Outlet, | ||
- useLoaderData, | ||
+ useRouteLoaderData, | ||
} from '@remix-run/react'; | ||
-import {Layout} from '~/components/Layout'; | ||
+import {PageLayout} from '~/components/PageLayout'; | ||
|
||
-export default function App() { | ||
+export function Layout({children}: {children?: React.ReactNode}) { | ||
const nonce = useNonce(); | ||
- const data = useLoaderData<typeof loader>(); | ||
+ const data = useRouteLoaderData<typeof loader>('root'); | ||
|
||
return ( | ||
<html> | ||
... | ||
<body> | ||
- <Layout {...data}> | ||
- <Outlet /> | ||
- </Layout> | ||
+ {data? ( | ||
+ <PageLayout {...data}>{children}</PageLayout> | ||
+ ) : ( | ||
+ children | ||
+ )} | ||
</body> | ||
</html> | ||
); | ||
} | ||
|
||
+export default function App() { | ||
+ return <Outlet />; | ||
+} | ||
|
||
export function ErrorBoundary() { | ||
const rootData = useLoaderData<typeof loader>(); | ||
|
||
return ( | ||
- <html> | ||
- ... | ||
- <body> | ||
- <Layout {...rootData}> | ||
- <div className="route-error"> | ||
- <h1>Error</h1> | ||
- ... | ||
- </div> | ||
- </Layout> | ||
- </body> | ||
- </html> | ||
+ <div className="route-error"> | ||
+ <h1>Error</h1> | ||
+ ... | ||
+ </div> | ||
); | ||
} | ||
|
||
``` |
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,5 @@ | ||
--- | ||
'@shopify/hydrogen': patch | ||
--- | ||
|
||
Update virtual route to use Layout component in the root file. |
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
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
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
Oops, something went wrong.