Skip to content

Fixed RemyAssistant.tsx - Where useeffect causes destroy is not a function error#446

Open
killerfrienddk wants to merge 4 commits into
TanStack:mainfrom
killerfrienddk:patch-1
Open

Fixed RemyAssistant.tsx - Where useeffect causes destroy is not a function error#446
killerfrienddk wants to merge 4 commits into
TanStack:mainfrom
killerfrienddk:patch-1

Conversation

@killerfrienddk
Copy link
Copy Markdown

@killerfrienddk killerfrienddk commented May 6, 2026

Reproduction:

  1. npx @tanstack/cli@latest create
  2. Select React
  3. Select ESLint
  4. Select Nitro
  5. Select Yes
  6. Choose Shadcn, Table and Query.
  7. Select Events
  8. Select Yes
  9. Select Yes
  10. Do an npm install
  11. Do an npm run dev
  12. Navigate to any page that is not docs ;)
image image

I changed:
useEffect(() => { return showRemyAssistant.subscribe(() => { setIsOpen(showRemyAssistant.state) }) }, [])

to:
useEffect(() => { const subscription = showRemyAssistant.subscribe(() => { setIsOpen(showRemyAssistant.state) }) return () => subscription.unsubscribe() }, [])

Summary by CodeRabbit

  • Refactor
    • Improved internal state synchronization within the RemyAssistant component; implementation changed for cleaner subscription handling. No user-facing behavior changes.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 6, 2026

📝 Walkthrough

Walkthrough

The effect synchronizing showRemyAssistant with local isOpen was refactored to store the subscription in a local subscription variable and return a cleanup that calls subscription.unsubscribe().

Changes

RemyAssistant subscription handling

Layer / File(s) Summary
Effect subscription and explicit cleanup
packages/create/src/frameworks/react/examples/events/assets/src/components/RemyAssistant.tsx
The useEffect no longer returns the showRemyAssistant.subscribe(...) call directly. Instead it assigns the subscription to subscription and returns a cleanup function that calls subscription.unsubscribe() to unsubscribe on cleanup.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I watched the hook tidy up its thread,
A subscription stored, with cleanup said.
Now unsubscribe hums when component parts part,
A small, neat ending — straight from my heart.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately identifies the specific bug being fixed ('destroy is not a function error') and the affected file (RemyAssistant.tsx), directly matching the core issue addressed in the PR.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@packages/create/src/frameworks/react/examples/events/assets/src/components/RemyAssistant.tsx`:
- Around line 91-94: The component currently calls
showRemyAssistant.subscribe(...) in the component body causing listener leaks
and render storms; move the subscription into a useEffect that runs on mount,
capture the returned Subscription and call subscription.unsubscribe() in the
effect cleanup, and keep setIsOpen inside the subscription callback;
alternatively (preferred) import and use the `@tanstack/react-store` useStore hook
to subscribe automatically and remove the duplicated local state and manual
subscribe/unsubscribe logic (references: showRemyAssistant, setIsOpen,
subscribe, unsubscribe, useEffect, useStore).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: de3939c1-82ac-4a01-87fa-e785d35e0ced

📥 Commits

Reviewing files that changed from the base of the PR and between 5bbccb0 and 2bcae52.

📒 Files selected for processing (1)
  • packages/create/src/frameworks/react/examples/events/assets/src/components/RemyAssistant.tsx

…use effect

I have now studied up more regarding useeffect and understand why coderabbit said what it said
@killerfrienddk killerfrienddk marked this pull request as draft May 12, 2026 07:21
@killerfrienddk killerfrienddk marked this pull request as ready for review May 12, 2026 07:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant