Skip to content

feat: add check-parent-suspense ESLint rule - #1738

Open
manudeli with Copilot wants to merge 8 commits into
mainfrom
copilot/fix-1654
Open

manudeli with Copilot wants to merge 8 commits into
mainfrom
copilot/fix-1654

Conversation

Copilot AI commented Sep 17, 2025 •

Copy link
Copy Markdown
Contributor

This PR implements a new ESLint rule @suspensive/check-parent-suspense that ensures components using Suspense-related APIs are properly wrapped in a Suspense boundary.

What it does

The rule detects usage of Suspense-related APIs and validates they are wrapped in a <Suspense> component:

Detected APIs:

  • Hooks: useSuspenseQuery, useSuspenseInfiniteQuery, useSuspenseQueries
  • Components: SuspenseQuery, SuspenseInfiniteQuery, SuspenseQueries
  • Lazy Components: Components created with lazy() function

Configuration

The rule is enabled by default in React TypeScript configurations but disabled for all files in packages/** to exempt library code from the check while still enforcing it in application code and examples.

Examples

❌ Before (produces errors):

function MyComponent() {
  const data = useSuspenseQuery(queryOptions) // Error: missing Suspense wrapper
  return <div>{data}</div>
}

function App() {
  return <SuspenseQuery>{data => <div>{data}</div>}</SuspenseQuery> // Error: missing Suspense wrapper
}

✅ After (correct usage):

function MyComponent() {
  return (
    <Suspense fallback={<div>Loading...</div>}>
      <div>
        {(() => {
          const data = useSuspenseQuery(queryOptions)
          return <div>{data}</div>
        })()}
      </div>
    </Suspense>
  )
}

function App() {
  return (
    <Suspense fallback={<div>Loading...</div>}>
      <SuspenseQuery>{data => <div>{data}</div>}</SuspenseQuery>
    </Suspense>
  )
}

Implementation details

  • Location: configs/eslint-config/rules/check-parent-suspense.js
  • Integration: Added to @suspensive/eslint-config and enabled by default in React TypeScript configurations
  • Package Exemption: Disabled for packages/**/*.{ts,tsx} files to allow library components that are designed to be used within Suspense boundaries
  • Configurable: Supports custom hook names, component names, and Suspense wrapper names
  • Comprehensive testing: Full test suite with valid/invalid cases
  • Documentation: Complete rule documentation with examples and configuration options

Recent Updates

  • ✅ Successfully rebased onto latest main (includes commits through e34d368)
  • ✅ Resolved merge conflicts in configs/eslint-config/package.json and pnpm-lock.yaml
  • ✅ All ESLint rule tests passing after rebase
  • ✅ Package exemptions preserved - rule disabled for packages/**/*.{ts,tsx} files

Real-world impact

The rule successfully identified several legitimate issues in the existing codebase where Suspense-related APIs were used without proper Suspense boundaries, demonstrating its practical value for preventing runtime errors.

For cases where the rule is too strict, developers can use // eslint-disable-next-line @suspensive/check-parent-suspense to disable the rule locally, though this is typically not needed since library code in packages is automatically exempted.

Fixes #1654.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@vercel

vercel Bot commented Sep 17, 2025 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
suspensive-next-streaming-react-query Ready Ready Preview Sep 8, 2026 7:56am UTC
v2.suspensive.org Ready Ready Preview Sep 8, 2026 7:56am UTC
v3.suspensive.org Ready Ready Preview Sep 8, 2026 7:56am UTC
visualization.suspensive.org Ready Ready Preview Sep 8, 2026 7:56am UTC

Request Review

@changeset-bot

changeset-bot Bot commented Sep 17, 2025 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 4fbf103

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copilot AI and others added 2 commits September 17, 2025 14:47
Co-authored-by: manudeli <61593290+manudeli@users.noreply.github.com>
Co-authored-by: manudeli <61593290+manudeli@users.noreply.github.com>
…ntation

Co-authored-by: manudeli <61593290+manudeli@users.noreply.github.com>
@manudeli

Copy link
Copy Markdown
Contributor

@copilot rebase please

@coauthors

coauthors Bot commented Sep 24, 2025 •

Copy link
Copy Markdown

People can be co-author:

Candidate Reasons Count Add this as commit message
@manudeli #1738 (comment) #1738 (review) #1738 (comment) #1738 (comment) #1738 (comment) #1738 (comment) #1738 (comment) 7 Co-authored-by: manudeli <61593290+manudeli@users.noreply.github.com>
@Copilot #1738 (comment) #1738 (comment) #1738 (comment) #1738 (comment) #1738 5 Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
@2-NOW #1738 (comment) 1 Co-authored-by: 2-NOW <71202076+2-NOW@users.noreply.github.com>
@gwansikk #1738 (comment) 1 Co-authored-by: gwansikk <39869096+gwansikk@users.noreply.github.com>

}) => <>{children(useSuspenseInfiniteQuery(options))}</>
}) => (
<>
{/* eslint-disable-next-line @suspensive/check-parent-suspense */}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@copilot In packages/*, ignore this eslint rule

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've disabled the @suspensive/check-parent-suspense rule for all files in packages/**/*.{ts,tsx} by adding a configuration block to the ESLint config and removing the individual eslint-disable comments from 13 files across the packages.

The rule is now ignored in all packages while still being enforced in examples and application code.

Commit: 2146269

Co-authored-by: manudeli <61593290+manudeli@users.noreply.github.com>
@2-NOW

2-NOW commented Sep 26, 2025

Copy link
Copy Markdown
Contributor

@2-NOW Could you review this with me? because this is your idea initially

Sure! Thank you for giving me the opportunity.

@manudeli

Copy link
Copy Markdown
Contributor

@copilot resolve conflict

Copilot AI commented Sep 26, 2025

Copy link
Copy Markdown
Contributor Author

@copilot resolve conflict

I've successfully resolved the merge conflicts and rebased the branch onto the latest main. The conflicts were in:

  • configs/eslint-config/package.json: Updated typescript-eslint version to ^8.43.0
  • pnpm-lock.yaml: Regenerated after resolving dependency conflicts

The rebase is complete and all ESLint rule tests are still passing. The branch is now up to date with the latest main branch changes.

Commit: 0ded5c5

@gwansikk

Copy link
Copy Markdown
Collaborator

I love it! I really hope this works. I'll review it as well!

@manudeli
manudeli requested a balanced review from Copilot September 8, 2026 07:44
@manudeli

manudeli commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

@copilot rebase this

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Hook-boundary analysis produces false results, and the package exemption does not apply during package-local lint runs.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details

Files not reviewed (1)

  • pnpm-lock.yaml: Generated file

Suppressed comments (1)

configs/eslint-config/rules/check-parent-suspense.js:98

  • Matching only the callee's spelling does not reliably detect the configured API. import { useSuspenseQuery as useQuery } ...; useQuery() is missed, while an unrelated locally declared useSuspenseQuery() is reported; member expressions have the same shadowing problem. Resolve the binding/import (and apply the same approach to configured JSX components and lazy) so aliases and unrelated symbols are handled correctly.
      } else if (node.callee.type === 'MemberExpression' && node.callee.property.type === 'Identifier') {
        name = node.callee.property.name
      }

      return name && suspenseHooks.has(name)
  • Files reviewed: 17/18 changed files
  • Comments generated: 2
  • Review effort level: Balanced

Comment on lines +72 to +76
let parent = node.parent
while (parent) {
if (parent.type === 'JSXElement' && parent.openingElement && parent.openingElement.name) {
const elementName = getJSXElementName(parent.openingElement.name)
if (suspenseWrappers.has(elementName)) {
Comment on lines +143 to +147
{
files: ['packages/**/*.{ts,tsx}'],
rules: {
'@suspensive/check-parent-suspense': 'off',
},
Copilot AI and others added 2 commits September 8, 2026 07:50
# Conflicts:
#	configs/eslint-config/index.js
#	configs/eslint-config/package.json
#	examples/next-streaming-react-query/src/app/page.tsx
#	examples/visualization/src/app/react/zodSearchParams/page.tsx
#	examples/vite-react-18-suspense-prerender-siblings-problem/tsconfig.tsbuildinfo
#	pnpm-lock.yaml

Co-authored-by: manudeli <61593290+manudeli@users.noreply.github.com>

Copilot AI commented Sep 8, 2026

Copy link
Copy Markdown
Contributor Author

@copilot rebase this

Merged the latest main into this branch and resolved conflicts.

Commits:

  • 7c9d179 (merge origin/main into copilot/fix-1654)
  • 4fbf103 (follow-up: restore eslint-config test deps after merge)

This branch was successfully deployed

4 active deployments
Preview – v2.suspensive.org — 4fbf1038 Deployed Sep 8, 2026 by vercel[bot]
Preview – v3.suspensive.org — 4fbf1038 Deployed Sep 8, 2026 by vercel[bot]
Preview – visualization.suspensive.org — 4fbf1038 Deployed Sep 8, 2026 by vercel[bot]
Preview – suspensive-next-streaming-react-query — 4fbf1038 Deployed Sep 8, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: check-parent-suspense eslint rule

8 participants