-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor(nextjs): move current setup to `src/pages` for convenience * feat(nextjs): `appDir` compatible nextjs router instance * feat(nextjs): separate export at `/app` for `appDir` feature * feat(nextjs): add nextjs example with `appDir` * chore(live-previews): bump to `nextjs` 13 * chore(examples): bump to next 13 * refactor(examples): update component name * feat(nextjs): add `routercomponent` to `/app` router provider * chore: add changeset * chore: update check auth * chore: update changeset * chore: fix store incompatible prop type * docs: update live example link * chore: move nextjs examples to `examples/nextjs` * docs: add `app/` example to examples list * docs(nextjs): add `app` support section
- Loading branch information
Showing
90 changed files
with
1,281 additions
and
133 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,80 @@ | ||
--- | ||
"@pankod/refine-nextjs-router": major | ||
--- | ||
|
||
- Bumped Next.js to 13 | ||
- Added support for experimental `appDir` option in `next.config.js` to allow for the latest Next.js features. | ||
|
||
|
||
## `pages` directory | ||
|
||
Current support for `pages` directory has not changed and will continue to work as before. It will be supported as long as `Next.js` continues to support and prompts it as the stable way of working with `Next.js`. | ||
|
||
## `appDir` option | ||
|
||
`appDir` option is a new experimental feature in `Next.js` that introduces a bunch of new features. It is currently in beta and is not stable. It is not recommended to use it in production. But can be used alongside the current `pages` directory support. | ||
|
||
To use `appDir` option, you need to add it to your `next.config.js` file. | ||
|
||
```js | ||
// next.config.js | ||
module.exports = { | ||
/* ... */ | ||
experimental: { | ||
appDir: true, | ||
}, | ||
}; | ||
``` | ||
|
||
## Using `appDir` with **refine** | ||
|
||
We've needed to make some changes to the `@pankod/refine-nextjs-router` to make it work with the current structure of the `app` directory feature. To make sure these do not break the current support for `pages` directory, we've added a new exports at the sub path `@pankod/refine-nextjs-router/app` that can be used with the `appDir` option. | ||
|
||
**Note** | ||
|
||
To make optional catch-all routes to work with the `app` directory, you need to define them as directories unlike the option of defining them as files with `pages` directory. | ||
|
||
You need to use `NextRouteComponent` from `@pankod/refine-nextjs-router/app` instead of `NextRouteComponent` from `@pankod/refine-nextjs-router` when using `appDir` option. | ||
|
||
Inside your `layout` file, you need to bind `params` to `routerProvider` to make sure `@pankod/refine-nextjs-router` can work properly with the new structure. | ||
|
||
```tsx | ||
// app/[[...refine]]/layout.tsx | ||
"use client"; | ||
|
||
import routerProvider from "@pankod/refine-nextjs-router/app"; | ||
|
||
const Layout = ({ children, params }) => { | ||
return ( | ||
<Refine | ||
routerProvider={routerProvider.apply({ params })} | ||
/* ... */ | ||
> | ||
{children} | ||
</Refine> | ||
); | ||
}; | ||
``` | ||
|
||
**Warning** | ||
|
||
Please note that, unlike the `routerProvider` from the `@pankod/refine-nextjs-router`, `routerProvider` from `@pankod/refine-nextjs-router/app` is a function and you need to bind `params` to make it work properly. | ||
|
||
```tsx | ||
// app/[[...refine]]/page.tsx | ||
|
||
"use client"; | ||
|
||
import { NextRouteComponent } from "@pankod/refine-nextjs-router/app"; | ||
|
||
export default NextRouteComponent; | ||
|
||
``` | ||
|
||
**Warning** | ||
|
||
You need to add `"use client";` directive to both `layout.tsx` and `page.tsx` inside `app/[[...refine]]` directory. | ||
|
||
**Warning** | ||
|
||
`checkAuthentication` does not work with `appDir`. We're aiming to release a substitute for it using middleware but for now its not included in this release. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
id: nextjs-appdir | ||
title: With `app/` Directory | ||
example-tags: [next.js,router-provider,antd,experimental] | ||
--- | ||
|
||
**refine** allows you to use the `app/` structure in your Next.js apps. To learn more about the `app/` directory, check out [Next.js beta docs](https://beta.nextjs.org/docs/upgrade-guide). In this example you will find how to use the `app/` directory with refine. | ||
|
||
[Refer to the refine Next.js documentation for more information. →](/docs/advanced-tutorials/ssr/nextjs.md) | ||
|
||
[View Next.js with `app/` Example Source](https://github.com/refinedev/refine/tree/master/examples/nextjs/appdir) | ||
|
||
<iframe loading="lazy" src="https://stackblitz.com/github/refinedev/refine/tree/master/examples/nextjs/appdir/?embed=1&view=preview&theme=dark&preset=node&ctl=1" | ||
style={{width: "100%", height:"80vh", border: "0px", borderRadius: "8px", overflow:"hidden"}} | ||
title="refine-nextjs-appdir-example" | ||
></iframe> |
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
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,64 @@ | ||
"use client"; | ||
|
||
import React from "react"; | ||
|
||
import { Refine } from "@pankod/refine-core"; | ||
import { | ||
notificationProvider, | ||
Layout, | ||
ErrorComponent, | ||
AuthPage, | ||
} from "@pankod/refine-antd"; | ||
import dataProvider from "@pankod/refine-simple-rest"; | ||
import routerProvider from "@pankod/refine-nextjs-router/app"; | ||
import "@pankod/refine-antd/dist/styles.min.css"; | ||
|
||
import "@styles/global.css"; | ||
|
||
import { authProvider } from "src/authProvider"; | ||
import { API_URL } from "../../src/constants"; | ||
|
||
import { PostList, PostCreate, PostEdit, PostShow } from "@components"; | ||
|
||
export default function RefineLayout({ | ||
children, | ||
params, | ||
}: { | ||
children: React.ReactNode; | ||
params: Record<"refine", string[]>; | ||
}) { | ||
return ( | ||
<Refine | ||
routerProvider={routerProvider.call({ params })} | ||
authProvider={authProvider} | ||
dataProvider={dataProvider(API_URL)} | ||
resources={[ | ||
{ | ||
name: "posts", | ||
list: PostList, | ||
create: PostCreate, | ||
edit: PostEdit, | ||
show: PostShow, | ||
canDelete: true, | ||
}, | ||
{ name: "users" }, | ||
]} | ||
options={{ syncWithLocation: true }} | ||
notificationProvider={notificationProvider} | ||
LoginPage={() => ( | ||
<AuthPage | ||
formProps={{ | ||
initialValues: { | ||
email: "admin@refine.dev", | ||
password: "password", | ||
}, | ||
}} | ||
/> | ||
)} | ||
Layout={Layout} | ||
catchAll={<ErrorComponent />} | ||
> | ||
{children} | ||
</Refine> | ||
); | ||
} |
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 @@ | ||
"use client"; | ||
|
||
import { NextRouteComponent } from "@pankod/refine-nextjs-router/app"; | ||
|
||
export default NextRouteComponent; |
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,11 @@ | ||
export default function RootLayout({ | ||
children, | ||
}: { | ||
children: React.ReactNode; | ||
}) { | ||
return ( | ||
<html lang="en"> | ||
<body>{children}</body> | ||
</html> | ||
); | ||
} |
File renamed without changes.
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,10 @@ | ||
/** @type {import('next').NextConfig} */ | ||
const nextConfig = { | ||
reactStrictMode: true, | ||
swcMinify: true, | ||
experimental: { | ||
appDir: true, | ||
}, | ||
}; | ||
|
||
module.exports = nextConfig; |
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,28 @@ | ||
{ | ||
"name": "refine-nextjs-appdir", | ||
"version": "3.25.0", | ||
"private": true, | ||
"scripts": { | ||
"start": "NODE_OPTIONS=--max_old_space_size=4096 PORT=3002 next dev", | ||
"build": "next build", | ||
"start:prod": "next start", | ||
"lint": "eslint '**/*.{js,jsx,ts,tsx}'" | ||
}, | ||
"dependencies": { | ||
"@pankod/refine-antd": "^3.64.2", | ||
"@pankod/refine-core": "^3.90.4", | ||
"@pankod/refine-nextjs-router": "^3.38.0", | ||
"@pankod/refine-simple-rest": "^3.37.4", | ||
"next": "^13.0.6", | ||
"nookies": "^2.5.2", | ||
"react": "^18.0.0", | ||
"react-dom": "^18.0.0" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^12.20.11", | ||
"@types/react": "^18.0.0", | ||
"@types/react-dom": "^18.0.0", | ||
"@typescript-eslint/parser": "^5.38.1", | ||
"typescript": "^4.7.4" | ||
} | ||
} |
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
Oops, something went wrong.