-
-
Notifications
You must be signed in to change notification settings - Fork 632
Improve error messages when component is missing 'use client' with RSC #2403
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
base: master
Are you sure you want to change the base?
Conversation
Remove leftover yalc-era pnpm-workspace.yaml from the Pro dummy app that caused pnpm to treat it as an isolated workspace root, preventing webpack binary resolution from the repo root node_modules/.bin/. Remove pinned @pmmmwh/[email protected] from dummy's devDependencies that conflicted with Shakapacker's 0.5.17 at root, causing the react-refresh loader to be applied twice in dev server mode. Fixes #2399 Co-Authored-By: Claude Opus 4.6 <[email protected]>
…ent' with RSC enabled When RSC support is enabled and a component is missing the 'use client' directive, the packs generator silently registers it as a server component. This causes cryptic runtime errors that never mention 'use client' as the root cause. This commit improves error messages at multiple layers: - Enrich wrapServerComponentRenderer (server & client) to include the component name and suggest adding 'use client' or using stream_react_component instead of react_component - Improve throwRailsContextMissingEntries generic error to mention 'use client' as the most common cause - Add build-time heuristic warning in packs generator that detects client-only APIs (hooks, event handlers, class components) in files classified as server components - Log RSC component classification summary during pack generation - Add explanatory comments in generated server component pack files Closes #2394 Co-Authored-By: Claude Opus 4.6 <[email protected]>
WalkthroughThe changes enhance error messaging and build-time detection for interactive components missing the 'use client' directive with RSC enabled. Component names are threaded through the server component registration pipeline, error messages are enriched with component context, and the packs generator introduces heuristic detection of client-side APIs in server components with warning feedback. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 🧹 Recent nitpick comments
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. Comment |
Greptile OverviewGreptile SummaryThis PR significantly improves the developer experience when React Server Components (RSC) support is enabled by providing actionable error messages at multiple layers (build-time and runtime) when interactive components are missing the Key Improvements
Changes MadeThe error message improvements span TypeScript (client/server wrappers), Ruby (packs generator), and test updates. Additionally, unused dependencies were cleaned up ( Implementation Quality
Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant User as Developer
participant Rails as Rails App
participant PackGen as PacksGenerator
participant Client as Client Bundle
participant Server as Server Bundle
participant Wrapper as wrapServerComponent
Note over User,Wrapper: Build Time
User->>Rails: Create component without 'use client'
Rails->>PackGen: bundle exec rake generate_packs
PackGen->>PackGen: Scan for 'use client' directive
alt Missing 'use client' + uses hooks/events
PackGen->>Rails: Rails.logger.warn (CLIENT_API_PATTERN matched)
end
PackGen->>Client: Generate pack with registerServerComponent
Note over Client: Comment added explaining server component classification
Note over User,Wrapper: Runtime - Server Side
User->>Rails: Request page with component
Rails->>Server: stream_react_component('Component')
Server->>Wrapper: wrapServerComponentRenderer called
Wrapper->>Wrapper: assertRailsContextWithServerStreamingCapabilities
alt Missing railsContext capabilities
Wrapper->>Rails: Throw error with component name + guidance
Rails->>User: Error: "Component 'X' cannot be rendered...<br/>Add 'use client' or use stream_react_component()"
end
Note over User,Wrapper: Runtime - Client Side
User->>Client: Hydrate component
Client->>Wrapper: wrapServerComponentRenderer (client version)
alt Missing domNodeId
Wrapper->>User: Error: "No domNodeId for 'Component'"
else Missing railsContext
Wrapper->>User: Error: "No railsContext for 'Component'<br/>Add 'use client' if component uses hooks/events"
end
|
size-limit report 📦
|
Summary
Closes #2394
When RSC support is enabled, components without
'use client'are silently classified as server components. If an interactive component (hooks, class components, event handlers) is missing this directive, it crashes at runtime with error messages that never mention the actual cause. This PR improves error messages at multiple layers:wrapServerComponentRenderernow catches the streaming context assertion failure and re-throws with the component name, suggesting either adding'use client'or usingstream_react_componentinstead ofreact_component'use client'guidancethrowRailsContextMissingEntriesnow lists missing'use client'as the most common cause instead of only suggesting config changesextends Component) and emits aRails.logger.warnwith specific API names foundBefore
After
Test plan
react-on-railsandreact-on-rails-procompile cleanly🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes
Chores