Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[New] addno-render-return-undefined: disallow components rendering undefined#3750

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
akulsr0 wants to merge14 commits intojsx-eslint:master
base:master
Choose a base branch
Loading
fromakulsr0:akul/no-render-return-undefined

Conversation

akulsr0
Copy link
Contributor

@akulsr0akulsr0 commentedMay 8, 2024
edited
Loading

Closes#3020

kevduc reacted with hooray emoji
@codecovCodecov
Copy link

codecovbot commentedMay 8, 2024
edited
Loading

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.45%. Comparing base(cef8123) to head(94e9817).
Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@##           master    #3750      +/-   ##==========================================- Coverage   97.62%   94.45%   -3.18%==========================================  Files         134      135       +1       Lines        9617     9708      +91       Branches     3488     3535      +47     ==========================================- Hits         9389     9170     -219- Misses        228      538     +310

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report?Share it here.

@akulsr0akulsr0 marked this pull request as ready for reviewMay 15, 2024 10:35
@ljharbljharb marked this pull request as draftMay 15, 2024 17:23
@akulsr0
Copy link
ContributorAuthor

@ljharb Let me know your thoughts on this!

ljharb reacted with eyes emoji

@akulsr0akulsr0 marked this pull request as ready for reviewMay 18, 2024 14:50

<!-- end auto-generated rule header -->

> In React 18, components may render undefined, and React will render nothing to the DOM instead of throwing an error. However, accidentally rendering nothing in a component could still cause surprises. This rule will warn if the `return` statement in a React Component returns undefined.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
>InReact 18, components may render undefined, and React will render nothing to the DOM instead of throwing an error. However, accidentally rendering nothing in a component could still cause surprises. This rule will warn if the`return` statement in a React Component returns undefined.
>Starting inReact 18, components may render`undefined`, and React will render nothing to the DOM instead of throwing an error. However, accidentally rendering nothing in a component could still cause surprises. This rule will warn if the`return` statement in a React Component returns`undefined`.

akulsr0 reacted with thumbs up emoji

> In React 18, components may render undefined, and React will render nothing to the DOM instead of throwing an error. However, accidentally rendering nothing in a component could still cause surprises. This rule will warn if the `return` statement in a React Component returns undefined.

Issue: [#3020](https://github.com/jsx-eslint/eslint-plugin-react/issues/3020)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

i'm not sure linking to the issue is needed

akulsr0 reacted with thumbs up emoji

## Rule Details

This rule will warn if the `return` statement in a React component returns undefined.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
This rule will warn if the`return` statement in a React component returns undefined.
This rule will warn if the`return` statement in a React component returns`undefined`.

akulsr0 reacted with thumbs up emoji

This rule will warn if the `return` statement in a React component returns undefined.

Examples of **incorrect** code for this rule:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

let's add one that usesvoid

akulsr0 reacted with thumbs up emoji
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

ping

@ljharbljharb marked this pull request as draftMay 24, 2024 16:34
@akulsr0akulsr0force-pushed theakul/no-render-return-undefined branch from6d3cfec tod1814c1CompareMay 25, 2024 05:13
@akulsr0
Copy link
ContributorAuthor

I've pushed the review changes

@akulsr0akulsr0 marked this pull request as ready for reviewJune 6, 2024 16:31
@akulsr0
Copy link
ContributorAuthor

Bumping this up!

ljharb reacted with eyes emoji

Copy link
Member

@ljharbljharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

There's still some unaddressed comments on the docs.

@ljharbljharb marked this pull request as draftJune 20, 2024 20:47
@ljharbljharb changed the title[Feat]no-render-return-undefined: disallow components rendering undefined[New] addno-render-return-undefined: disallow components rendering undefinedJun 20, 2024

This rule will warn if the `return` statement in a React component returns undefined.

Examples of **incorrect** code for this rule:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

ping

Comment on lines +31 to +38
function getUI() {
if (condition) return <h1>Hello</h1>;
}
function App() {
return getUI();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yes, I don't think we necessarily have to support this - I'm saying that the docs should be updated to reflect the caveats.

Comment on lines +33 to +35
const value = returnIdentifierVar.defs[0].node.init;
if (
returnIdentifierVar.defs[0].node
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

if line 35 is nullish, then line 33 will throw - i think this needs to be checked before accessing.init

const isCalleeObjArray = calleeObjNode.defs[0].node.init.type === 'ArrayExpression';
const isMapCall = isCalleeObjArray && calleePropertyName === 'map';
if (isMapCall) {
const mapCallback = returnNode.arguments[0];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

can you add a test for an SFC that omitsreturn entirely?

return value;
}

switch (returnNode.type) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

let's use an if/else here instead of a switch

Comment on lines +188 to +191
function App() {
return null;
}
`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
functionApp(){
returnnull;
}
`,
functionApp(){
returnnull;
}
`,

similar changes on all the code snippets

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@ljharbljharbljharb requested changes

Requested changes must be addressed to merge this pull request.

Assignees
No one assigned
Labels
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

React 18: Warn when components renderundefined
2 participants
@akulsr0@ljharb

[8]ページ先頭

©2009-2025 Movatter.jp