Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The sorter will incorrectly move the "use client" / "use strict" directive (Next 13), even if a prettier-ignore flag is set. #185

Closed
jornki opened this issue Oct 30, 2022 · 2 comments · Fixed by #186

Comments

@jornki
Copy link

jornki commented Oct 30, 2022

Your Environment

  • Prettier version: 2.7.1
  • node version 16.17.0:
  • package manager: yarn
  • IDE: VScode
  • Plugin version: 3.4.0

Describe the bug

Consider the following code:

"use client";

import { useState } from "react";

export default function Test() {
	return <p>Test</p>;
}

On format, the «prettier-plugin-sort-imports», will move the "use client"; directive below the imports, prettier will then wrap it in parenthesis since it's not at the top of file. This breaks client components in Next 13. The same happens when using the use strict; directive.

Adding «// prettier-ignore» above the "use client"; directive does nothing. This part is probably related to #112.

To Reproduce

Use the code snippet above and run prettier --write .

Expected behavior

The "use client"; directive should be left at the top of the file.

@danieljvdm
Copy link

Discussion here: #182

@alexllao
Copy link

alexllao commented Nov 9, 2022

Any solution?

broofa added a commit to broofa/prettier-plugin-sort-imports that referenced this issue Nov 13, 2022
byara added a commit that referenced this issue Nov 24, 2022
keep script directives at top of file, fixes #185
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants