Skip to content
Fallow home
All docs pages

Docs home

Misplaced directives

What a misplaced-directive finding of fallow dead-code means, why it matters and how to fix it.

What it reports

"use client" / "use server" directive is not in the leading position and is ignored.

Architecture explains how fallow finds it.

Why it matters

A "use client" or "use server" directive string appears as an expression statement after a non-directive statement (an import, a const). React Server Components bundlers only honor a directive in the leading prologue, before any other statement; once any statement precedes it the string is parsed as an ordinary expression and silently ignored. The intended client/server boundary never takes effect, so the file is treated as a server module. To fix: move the directive to the very top of the file, above every import. The check runs only when the project declares a React Server Components bundler: next, waku, @lazarv/react-server, react-server-dom-webpack, react-server-dom-vite, react-server-dom-parcel or @vitejs/plugin-rsc.

Example

A file has import { useState } from 'react'; on line 1 and "use client"; on line 2.

Fix

Move the directive to the first line of the file, above every import.

Facts

FactValue
Issue typemisplaced-directive
Rule id in SARIF outputfallow/misplaced-directive
Commandfallow dead-code
Default severitywarn
Config key in rulesmisplaced-directive
Suppression comment// fallow-ignore-next-line misplaced-directive
Fixable with fallow fixNo
Opt-inNo

Note. Requires the project to declare a React Server Components bundler, such as next, waku or @vitejs/plugin-rsc.

When to keep the code

  • Only when the string is not meant as a directive. This is rare.

Notes

The rule runs when the project declares a bundler for React Server Components: next, waku, @lazarv/react-server, @vitejs/plugin-rsc or a react-server-dom-* package.