Skip to content

Commit

Permalink
Disallow multiple server directives at the same level (file or functi…
Browse files Browse the repository at this point in the history
…on) (#73018)

This PR has two main goals:

- **Consolidate the detection of server directives in modules and function bodies.** Previously, these were two separate implementations with significant overlap, but also some [questionable discrepancies](#72811 (comment)).
- **Model the current directive (in a file or function) using an enum instead of two separate booleans.** This change prevents any confusion that both directives might be present simultaneously. Additionally, we're now emitting an error if multiple directives (`"use server"` and `"use cache"`) are defined in the same location (at the top of a file or function body).

A mixed usage of `"use server"` and `"use cache"` _across different locations_ is still allowed, e.g. `"use cache"` at the top of a file, and `"use server"` in a function.

> [!NOTE]  
> The diff may be tricky to review because chunks from two different functions are combined into a single function. Fortunately, we have comprehensive test coverage for the transforms, which instills high confidence that these changes are correct.
  • Loading branch information
unstubbable authored Nov 22, 2024
1 parent 27961cf commit 04adb76
Show file tree
Hide file tree
Showing 18 changed files with 500 additions and 441 deletions.
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ crates/next-custom-transforms/tests/errors/react-server-components/client-graph/
crates/next-custom-transforms/tests/errors/react-server-components/server-graph/fake-client-entry/input.js
crates/next-custom-transforms/tests/errors/server-actions/server-graph/8/input.js
crates/next-custom-transforms/tests/errors/server-actions/server-graph/9/input.js
crates/next-custom-transforms/tests/errors/server-actions/server-graph/18/input.js
crates/next-custom-transforms/tests/fixture/optimize-barrel/normal/4/input.js
crates/next-custom-transforms/tests/fixture/react-server-components/client-graph/client-entry/input.js
crates/next-custom-transforms/tests/fixture/react-server-components/server-graph/client-entry/input.js
Expand Down
Loading

0 comments on commit 04adb76

Please sign in to comment.