fix: not displaying initially selected text#343
Conversation
✅ Deploy Preview for graypaper-reader ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
WalkthroughA refactoring that extracts text layer rendering detection logic into a new custom hook Changes
Sequence DiagramsequenceDiagram
participant SR as SelectionRenderer
participant Hook as useIsCurrentPageRendered
participant SC as SelectionContext
participant PC as PdfContext
participant EB as EventBus
SR->>Hook: Calls useIsCurrentPageRendered()
Hook->>SC: Reads pageNumber
Hook->>PC: Reads textLayerRenderedRef, eventBus
alt pageNumber exists
Hook->>Hook: Check if pageNumber in textLayerRenderedRef.current
activate Hook
Hook->>Hook: Set isCurrentPageTextLayerRendered
deactivate Hook
else pageNumber is null
Hook->>Hook: Reset isCurrentPageTextLayerRendered to false
end
opt eventBus available
Hook->>EB: Subscribe to textlayerrendered event
EB-->>Hook: Event fired (event.pageNumber matches)
activate Hook
Hook->>Hook: Set isCurrentPageTextLayerRendered = true
deactivate Hook
end
Hook-->>SR: Return isCurrentPageTextLayerRendered
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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 |
df0297c to
1b6005e
Compare
1b6005e to
cc00a54
Compare
Visual Regression Test Report ✅ PassedGithub run id: 19412563062 🔗 Artifacts: Download |
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/components/PdfViewer/SelectionRenderer/SelectionRenderer.tsx(3 hunks)src/components/PdfViewer/SelectionRenderer/useIsCurrentPageRendered.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{js,jsx,ts,tsx}
⚙️ CodeRabbit configuration file
When reviewing Tailwind CSS classes, ensure they follow Tailwind 4.x conventions and suggest modern 4.x alternatives for deprecated patterns.
Files:
src/components/PdfViewer/SelectionRenderer/useIsCurrentPageRendered.tssrc/components/PdfViewer/SelectionRenderer/SelectionRenderer.tsx
🧠 Learnings (4)
📓 Common learnings
Learnt from: chmurson
Repo: FluffyLabs/graypaper-reader PR: 333
File: src/components/PdfProvider/PdfProvider.tsx:34-37
Timestamp: 2025-10-28T20:41:06.887Z
Learning: In the graypaper-reader codebase, for text layer render tracking in PdfProvider, use RefObject<number[]> approach (textLayerRenderedRef) without adding reactive signals or version numbers. Consumers should check the ref imperatively when needed rather than reacting to changes.
📚 Learning: 2025-10-28T20:41:06.887Z
Learnt from: chmurson
Repo: FluffyLabs/graypaper-reader PR: 333
File: src/components/PdfProvider/PdfProvider.tsx:34-37
Timestamp: 2025-10-28T20:41:06.887Z
Learning: In the graypaper-reader codebase, for text layer render tracking in PdfProvider, use RefObject<number[]> approach (textLayerRenderedRef) without adding reactive signals or version numbers. Consumers should check the ref imperatively when needed rather than reacting to changes.
Applied to files:
src/components/PdfViewer/SelectionRenderer/useIsCurrentPageRendered.tssrc/components/PdfViewer/SelectionRenderer/SelectionRenderer.tsx
📚 Learning: 2025-10-22T20:36:10.440Z
Learnt from: chmurson
Repo: FluffyLabs/graypaper-reader PR: 330
File: src/components/Outline/OutlineLink.tsx:17-21
Timestamp: 2025-10-22T20:36:10.440Z
Learning: Project targets React 19+; prefer passing refs as a regular prop in function components and avoid React.forwardRef in new code. File: src/components/Outline/OutlineLink.tsx.
Applied to files:
src/components/PdfViewer/SelectionRenderer/SelectionRenderer.tsx
📚 Learning: 2025-10-22T20:36:10.440Z
Learnt from: chmurson
Repo: FluffyLabs/graypaper-reader PR: 330
File: src/components/Outline/OutlineLink.tsx:17-21
Timestamp: 2025-10-22T20:36:10.440Z
Learning: This repo targets React 19+; prefer passing refs as a normal prop to function components and avoid React.forwardRef in new code. File context: src/components/Outline/OutlineLink.tsx.
Applied to files:
src/components/PdfViewer/SelectionRenderer/SelectionRenderer.tsx
🧬 Code graph analysis (2)
src/components/PdfViewer/SelectionRenderer/useIsCurrentPageRendered.ts (2)
src/components/PdfProvider/PdfProvider.tsx (2)
PdfContext(13-13)IPdfContext(27-37)src/components/SelectionProvider/SelectionProvider.tsx (2)
SelectionContext(35-35)ISelectionContext(21-29)
src/components/PdfViewer/SelectionRenderer/SelectionRenderer.tsx (4)
src/components/PdfViewer/Highlighter/Highlighter.tsx (1)
IHighlighterColor(12-16)src/components/PdfProvider/PdfProvider.tsx (2)
PdfContext(13-13)IPdfContext(27-37)src/components/SelectionProvider/SelectionProvider.tsx (2)
SelectionContext(35-35)ISelectionContext(21-29)src/components/PdfViewer/SelectionRenderer/useIsCurrentPageRendered.ts (1)
useIsCurrentPageRendered(5-38)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: visual-tests
🔇 Additional comments (3)
src/components/PdfViewer/SelectionRenderer/SelectionRenderer.tsx (1)
7-7: LGTM! Clean refactoring that improves separation of concerns.The extraction of text layer render detection into a dedicated hook makes the component cleaner and the logic more reusable. The hook properly encapsulates both imperative ref checking and event-driven updates.
Also applies to: 14-20, 64-66, 111-111
src/components/PdfViewer/SelectionRenderer/useIsCurrentPageRendered.ts (2)
19-33: LGTM! Event subscription correctly handles dynamic text layer rendering.The event-driven approach ensures the state updates when new pages are rendered, properly handling the async nature of text layer rendering. Cleanup is correctly implemented.
5-38: Good approach: imperative ref checking + event subscription.The hook correctly implements the pattern from learnings by checking the ref imperatively when needed (on pageNumber change) and using events for updates, rather than trying to make the ref itself reactive. This should fix the initially selected text display issue.
[Based on learnings]
|
When testing I feel that the previous selection is just left as-is, yet the note that we cannot selection for is correctly activated. However, is it possible to reset the selection in case it cannot be found? Or maybe default to page/section first block or sth? |
Summary by CodeRabbit