From 53546a7189f99c1a0deff2e5cdbd02a9edcdecf0 Mon Sep 17 00:00:00 2001 From: xiaoyu2er Date: Tue, 10 Jun 2025 15:28:23 +0000 Subject: [PATCH] docs: update nextjs documentation --- .../03-server-actions-and-mutations.mdx | 562 ---------------- .../02-data-fetching/index.mdx | 6 - .../02-file-conventions/middleware.mdx} | 0 .../03-server-actions-and-mutations.mdx | 562 ---------------- .../02-data-fetching/index.mdx | 6 - .../02-file-conventions/middleware.mdx} | 0 .../02-project-structure.mdx | 2 +- .../01-getting-started/11-updating-data.mdx | 145 ++++- .../docs/01-app/02-guides/authentication.mdx | 6 +- .../02-guides/content-security-policy.mdx | 4 +- .../docs/01-app/02-guides/data-security.mdx | 470 ++++++++++++++ .../incremental-static-regeneration.mdx | 2 +- .../en/docs/01-app/02-guides/index.mdx | 6 +- .../01-app/02-guides/internationalization.mdx | 2 +- .../migrating/app-router-migration.mdx | 6 +- .../migrating/from-create-react-app.mdx | 2 +- .../01-app/02-guides/migrating/from-vite.mdx | 2 +- .../en/docs/01-app/02-guides/multi-zones.mdx | 2 +- .../en/docs/01-app/02-guides/prefetching.mdx | 359 +++++++++++ .../01-app/02-guides/production-checklist.mdx | 2 +- .../en/docs/01-app/02-guides/redirecting.mdx | 10 +- .../en/docs/01-app/02-guides/self-hosting.mdx | 2 +- .../02-guides/single-page-applications.mdx | 4 +- .../docs/01-app/02-guides/static-exports.mdx | 6 +- .../01-routing/13-route-handlers.mdx | 493 -------------- .../01-routing/14-middleware.mdx | 603 ------------------ .../03-server-actions-and-mutations.mdx | 564 ---------------- .../02-data-fetching/index.mdx | 4 - .../en/docs/01-app/04-deep-dive/caching.mdx | 8 +- .../05-api-reference/02-components/form.mdx | 2 +- .../05-api-reference/02-components/link.mdx | 2 +- .../03-file-conventions/01-metadata/index.mdx | 2 +- .../03-file-conventions/middleware.mdx | 588 ++++++++++++++++- .../route-segment-config.mdx | 2 +- .../03-file-conventions/route.mdx | 508 ++++++++++++++- .../05-api-reference/04-functions/after.mdx | 4 +- .../04-functions/cacheTag.mdx | 2 +- .../05-api-reference/04-functions/cookies.mdx | 8 +- .../05-api-reference/04-functions/fetch.mdx | 6 + .../04-functions/forbidden.mdx | 2 +- .../04-functions/generate-metadata.mdx | 22 +- .../04-functions/permanentRedirect.mdx | 4 +- .../04-functions/redirect.mdx | 4 +- .../04-functions/unauthorized.mdx | 2 +- .../04-functions/use-pathname.mdx | 2 +- .../05-config/01-next-config-js/appDir.mdx | 2 +- .../01-next-config-js/pageExtensions.mdx | 2 +- .../05-config/01-next-config-js/redirects.mdx | 2 +- .../02-guides/internationalization.mdx | 8 +- .../03-data-fetching/01-get-static-props.mdx | 2 +- .../03-forms-and-mutations.mdx | 2 +- .../02-file-conventions/middleware.mdx} | 2 +- .../03-functions/get-initial-props.mdx | 2 +- .../03-functions/get-server-side-props.mdx | 10 +- .../03-functions/get-static-paths.mdx | 14 +- .../03-functions/get-static-props.mdx | 2 +- .../03-server-actions-and-mutations.mdx | 562 ---------------- .../02-data-fetching/index.mdx | 6 - .../02-file-conventions/middleware.mdx} | 0 .../03-server-actions-and-mutations.mdx | 566 ---------------- .../02-data-fetching/index.mdx | 6 - .../02-file-conventions/middleware.mdx} | 0 .../03-server-actions-and-mutations.mdx | 563 ---------------- .../02-data-fetching/index.mdx | 6 - .../02-file-conventions/middleware.mdx} | 0 .../03-server-actions-and-mutations.mdx | 562 ---------------- .../02-data-fetching/index.mdx | 6 - .../02-file-conventions/middleware.mdx} | 0 .../03-server-actions-and-mutations.mdx | 562 ---------------- .../02-data-fetching/index.mdx | 6 - .../02-file-conventions/middleware.mdx} | 0 .../03-server-actions-and-mutations.mdx | 562 ---------------- .../02-data-fetching/index.mdx | 6 - .../02-file-conventions/middleware.mdx} | 0 74 files changed, 2145 insertions(+), 6316 deletions(-) delete mode 100644 apps/docs/content/ar/docs/01-app/03-building-your-application/02-data-fetching/03-server-actions-and-mutations.mdx delete mode 100644 apps/docs/content/ar/docs/01-app/03-building-your-application/02-data-fetching/index.mdx rename apps/docs/content/ar/docs/02-pages/{03-building-your-application/01-routing/11-middleware.mdx => 04-api-reference/02-file-conventions/middleware.mdx} (100%) delete mode 100644 apps/docs/content/de/docs/01-app/03-building-your-application/02-data-fetching/03-server-actions-and-mutations.mdx delete mode 100644 apps/docs/content/de/docs/01-app/03-building-your-application/02-data-fetching/index.mdx rename apps/docs/content/de/docs/02-pages/{03-building-your-application/01-routing/11-middleware.mdx => 04-api-reference/02-file-conventions/middleware.mdx} (100%) create mode 100644 apps/docs/content/en/docs/01-app/02-guides/data-security.mdx create mode 100644 apps/docs/content/en/docs/01-app/02-guides/prefetching.mdx delete mode 100644 apps/docs/content/en/docs/01-app/03-building-your-application/02-data-fetching/03-server-actions-and-mutations.mdx delete mode 100644 apps/docs/content/en/docs/01-app/03-building-your-application/02-data-fetching/index.mdx rename apps/docs/content/en/docs/02-pages/{03-building-your-application/01-routing/11-middleware.mdx => 04-api-reference/02-file-conventions/middleware.mdx} (88%) delete mode 100644 apps/docs/content/es/docs/01-app/03-building-your-application/02-data-fetching/03-server-actions-and-mutations.mdx delete mode 100644 apps/docs/content/es/docs/01-app/03-building-your-application/02-data-fetching/index.mdx rename apps/docs/content/es/docs/02-pages/{03-building-your-application/01-routing/11-middleware.mdx => 04-api-reference/02-file-conventions/middleware.mdx} (100%) delete mode 100644 apps/docs/content/fr/docs/01-app/03-building-your-application/02-data-fetching/03-server-actions-and-mutations.mdx delete mode 100644 apps/docs/content/fr/docs/01-app/03-building-your-application/02-data-fetching/index.mdx rename apps/docs/content/fr/docs/02-pages/{03-building-your-application/01-routing/11-middleware.mdx => 04-api-reference/02-file-conventions/middleware.mdx} (100%) delete mode 100644 apps/docs/content/ja/docs/01-app/03-building-your-application/02-data-fetching/03-server-actions-and-mutations.mdx delete mode 100644 apps/docs/content/ja/docs/01-app/03-building-your-application/02-data-fetching/index.mdx rename apps/docs/content/ja/docs/02-pages/{03-building-your-application/01-routing/11-middleware.mdx => 04-api-reference/02-file-conventions/middleware.mdx} (100%) delete mode 100644 apps/docs/content/ru/docs/01-app/03-building-your-application/02-data-fetching/03-server-actions-and-mutations.mdx delete mode 100644 apps/docs/content/ru/docs/01-app/03-building-your-application/02-data-fetching/index.mdx rename apps/docs/content/ru/docs/02-pages/{03-building-your-application/01-routing/11-middleware.mdx => 04-api-reference/02-file-conventions/middleware.mdx} (100%) delete mode 100644 apps/docs/content/zh-hans/docs/01-app/03-building-your-application/02-data-fetching/03-server-actions-and-mutations.mdx delete mode 100644 apps/docs/content/zh-hans/docs/01-app/03-building-your-application/02-data-fetching/index.mdx rename apps/docs/content/zh-hans/docs/02-pages/{03-building-your-application/01-routing/11-middleware.mdx => 04-api-reference/02-file-conventions/middleware.mdx} (100%) delete mode 100644 apps/docs/content/zh-hant/docs/01-app/03-building-your-application/02-data-fetching/03-server-actions-and-mutations.mdx delete mode 100644 apps/docs/content/zh-hant/docs/01-app/03-building-your-application/02-data-fetching/index.mdx rename apps/docs/content/zh-hant/docs/02-pages/{03-building-your-application/01-routing/11-middleware.mdx => 04-api-reference/02-file-conventions/middleware.mdx} (100%) diff --git a/apps/docs/content/ar/docs/01-app/03-building-your-application/02-data-fetching/03-server-actions-and-mutations.mdx b/apps/docs/content/ar/docs/01-app/03-building-your-application/02-data-fetching/03-server-actions-and-mutations.mdx deleted file mode 100644 index 5027fbd2..00000000 --- a/apps/docs/content/ar/docs/01-app/03-building-your-application/02-data-fetching/03-server-actions-and-mutations.mdx +++ /dev/null @@ -1,562 +0,0 @@ ---- -source-updated-at: 2025-06-01T01:32:20.000Z -translation-updated-at: 2025-06-02T20:13:19.659Z -title: إجراءات الخادم والتحولات -nav_title: إجراءات الخادم والتحولات -description: تعلم كيفية التعامل مع إرسال النماذج وتحولات البيانات باستخدام Next.js. -related: - description: تعلم كيفية تكوين إجراءات الخادم في Next.js - links: - - app/api-reference/config/next-config-js/serverActions ---- - -[إجراءات الخادم (Server Actions)](https://react.dev/reference/rsc/server-actions) هي **وظائف غير متزامنة** يتم تنفيذها على الخادم. يمكن استدعاؤها في مكونات الخادم والعميل للتعامل مع إرسال النماذج وتحولات البيانات في تطبيقات Next.js. - -> **🎥 شاهد:** تعلم المزيد عن التحولات باستخدام إجراءات الخادم → [YouTube (10 دقائق)](https://youtu.be/dDpZfOQBMaU?si=cJZHlUu_jFhCzHUg). - -## الاتفاقية - -يمكن تعريف إجراء الخادم باستخدام توجيه React [`"use server"`](https://react.dev/reference/react/use-server). يمكنك وضع التوجيه في أعلى دالة `async` لتمييز الدالة كإجراء خادم، أو في أعلى ملف منفصل لتمييز جميع الصادرات من ذلك الملف كإجراءات خادم. - -### مكونات الخادم - -يمكن لمكونات الخادم استخدام توجيه `"use server"` على مستوى الدالة المضمنة أو مستوى الوحدة. لتضمين إجراء خادم، أضف `"use server"` في أعلى جسم الدالة: - -```tsx filename="app/page.tsx" switcher -export default function Page() { - // إجراء الخادم - async function create() { - 'use server' - // تحويل البيانات - } - - return '...' -} -``` - -```jsx filename="app/page.js" switcher -export default function Page() { - // إجراء الخادم - async function create() { - 'use server' - // تحويل البيانات - } - - return '...' -} -``` - -### مكونات العميل - -لاستدعاء [دالة الخادم](/docs/app/getting-started/updating-data#server-functions) في مكون عميل، أنشئ ملفًا جديدًا وأضف توجيه `"use server"` في أعلى الملف. سيتم تمييز جميع الدوال المصدرة داخل الملف كدوال خادم يمكن إعادة استخدامها في كل من مكونات العميل والخادم: - -```tsx filename="app/actions.ts" switcher -'use server' - -export async function create() {} -``` - -```js filename="app/actions.js" switcher -'use server' - -export async function create() {} -``` - -```tsx filename="app/button.tsx" switcher -'use client' - -import { create } from './actions' - -export function Button() { - return -} -``` - -```jsx filename="app/button.js" switcher -'use client' - -import { create } from './actions' - -export function Button() { - return -} -``` - -### تمرير الإجراءات كخصائص - -يمكنك أيضًا تمرير إجراء خادم إلى مكون عميل كخاصية: - -```jsx - -``` - -```tsx filename="app/client-component.tsx" switcher -'use client' - -export default function ClientComponent({ - updateItemAction, -}: { - updateItemAction: (formData: FormData) => void -}) { - return
{/* ... */}
-} -``` - -```jsx filename="app/client-component.js" switcher -'use client' - -export default function ClientComponent({ updateItemAction }) { - return
{/* ... */}
-} -``` - -عادةً، سيشير ملحق TypeScript لـ Next.js إلى `updateItemAction` في `client-component.tsx` لأنه دالة لا يمكن عادةً تسلسلها عبر حدود العميل والخادم. ومع ذلك، يُفترض أن الخصائص المسماة `action` أو المنتهية بـ `Action` تتلقى إجراءات خادم. هذا مجرد استدلال لأن ملحق TypeScript لا يعرف فعليًا ما إذا كان يتلقى إجراء خادم أو دالة عادية. سيظل التحقق من النوع أثناء التشغيل يضمن عدم تمرير دالة إلى مكون عميل عن طريق الخطأ. - -## السلوك - -- يمكن استدعاء إجراءات الخادم باستخدام سمة `action` في عنصر `
`. - - تدعم مكونات الخادم التحسين التدريجي افتراضيًا، مما يعني أن النموذج سيتم إرساله حتى إذا لم يتم تحميل JavaScript بعد أو تم تعطيله. - - في مكونات العميل، ستقوم النماذج التي تستدعي إجراءات الخادم بجدولة عمليات الإرسال إذا لم يتم تحميل JavaScript بعد، مع إعطاء الأولوية لترطيب العميل. - - بعد الترطيب، لا يقوم المتصفح بالتحديث عند إرسال النموذج. -- لا تقتصر إجراءات الخادم على `` ويمكن استدعاؤها من معالج الأحداث، و`useEffect`، ومكتبات الطرف الثالث، وعناصر النموذج الأخرى مثل ` - - ) -} -``` - -```jsx filename="app/like-button.js" switcher -'use client' - -import { incrementLike } from './actions' -import { useState } from 'react' - -export default function LikeButton({ initialLikes }) { - const [likes, setLikes] = useState(initialLikes) - - return ( - <> -

Total Likes: {likes}

- - - ) -} -``` - -يمكنك أيضًا إضافة معالجات الأحداث إلى عناصر النموذج، على سبيل المثال، لحفظ حقل النموذج `onChange`: - -```tsx filename="app/ui/edit-post.tsx" -'use client' - -import { publishPost, saveDraft } from './actions' - -export default function EditPost() { - return ( - -