Transform inline "use server" functions inside file-level "use server" files

オープン
#1,372 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
50/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
静か
技術スタック
react, typescript
領域
build-system

調査の方向性

組み込みの Server Function transform から始め、モジュールレベルの "use server" ディレクティブとインラインの "use server" ディレクティブをどのように処理するかを追跡します。issue の例を再現用として使用し、その後、利用可能であれば既存の transform のカバレッジを調べます。outer と inner の両方が独立した Server Functions として登録され、inner を返すとシリアライズ可能なサーバー参照が生成されれば完了です。

索引モデルが issue の本文から書いたものです。

説明

plugin: rsc

The composability issue of file directive and inline directive is hinted in https://github.com/vitejs/vite-plugin-react/issues/1336 for use server/cache, but this is already an issue with same use server directives. Before jumping too focused on use server/cache composition, we should evaluate the design for use server separately.

It may be a low priority if it's not used in practice, but it's good to be aware that there's a general Next.js transform approach divergence.

EDIT: It turned out Next.js doesn't support fully due to runtime side issue:
https://github.com/hi-ogawa/reproductions/tree/main/next-rsc-returned-nested-action


Description

The built-in Server Function transform currently chooses between handling a module-level "use server" directive and handling inline "use server" directives. When a file has the module directive, it wraps the module exports but does not hoist and register explicitly annotated local functions inside those exports.

For example:

'use server'

export async function outer() {
  async function inner() {
    'use server'
    return 'inner result'
  }

  return inner
}

outer is exported and inherits the module-level role. inner is local, so it does not inherit that role, but its own inline directive explicitly declares it as a Server Function. The expected result is that outer and inner are independently registered Server Functions and that calling outer can return inner as a serializable server reference.

The current transform registers only outer. It leaves inner as an ordinary nested function, including the inert directive string in its body. Returning that function through React therefore does not produce a registered server reference.

主要言語
TypeScript
スター
1.2k
フォーク
287
平均マージ
1日 19時間
マージ済み PR(30日)
21

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

vitejs/vite-plugin-react のほかの issue

vitejs/vite-plugin-react の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。