fix: JSONL files not opening in preview (ASTD-261)#427
Conversation
The backend HEAD endpoint returns application/octet-stream for all files, causing useIsBinaryFile to incorrectly classify .jsonl and other text files as binary. Added KNOWN_TEXT_EXTENSIONS allowlist that short-circuits the HEAD request for recognized text extensions. - Add 50+ known text extensions (json, jsonl, csv, py, yaml, md, etc.) - Restructure hook to check text extensions before binary blocklist - Add unit tests for useIsBinaryFile hook Signed-off-by: mschwab <mschwab@nvidia.com>
📝 WalkthroughWalkthrough
ChangesuseIsBinaryFile known-text fast path and tests
Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
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 `@web/packages/studio/src/components/filesets/hooks/useIsBinaryFile.test.ts`:
- Line 5: The import statement on line 5 mixes value and type imports from
`@tanstack/react-query`. Separate UseQueryResult into a type-only import using
import type syntax, keeping useQuery in the regular import statement. This
follows coding guidelines by explicitly marking type-only imports and allows the
compiler to properly tree-shake unused types.
🪄 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: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: b07f9cd4-47a7-49c2-946c-0a532a0b5fee
📒 Files selected for processing (2)
web/packages/studio/src/components/filesets/hooks/useIsBinaryFile.test.tsweb/packages/studio/src/components/filesets/hooks/useIsBinaryFile.ts
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import { useIsBinaryFile } from '@studio/components/filesets/hooks/useIsBinaryFile'; | ||
| import { useQuery, UseQueryResult } from '@tanstack/react-query'; |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Separate type-only imports.
UseQueryResult is only used as a type. Per coding guidelines, use import type for type-only imports.
📦 Suggested fix
-import { useQuery, UseQueryResult } from '`@tanstack/react-query`';
+import { useQuery } from '`@tanstack/react-query`';
+import type { UseQueryResult } from '`@tanstack/react-query`';📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| import { useQuery, UseQueryResult } from '@tanstack/react-query'; | |
| import { useQuery } from '`@tanstack/react-query`'; | |
| import type { UseQueryResult } from '`@tanstack/react-query`'; |
🤖 Prompt for 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.
In `@web/packages/studio/src/components/filesets/hooks/useIsBinaryFile.test.ts` at
line 5, The import statement on line 5 mixes value and type imports from
`@tanstack/react-query`. Separate UseQueryResult into a type-only import using
import type syntax, keeping useQuery in the regular import statement. This
follows coding guidelines by explicitly marking type-only imports and allows the
compiler to properly tree-shake unused types.
Source: Coding guidelines
|
Problem
JSONL files were showing 'Text preview not available for binary files' in the fileset preview panel.
Root Cause
The backend HEAD endpoint returns
application/octet-streamfor all files.useIsBinaryFilerelied solely on theContent-Typeheader to determine if a file is text, so.jsonl(and other text files like.json,.csv,.py, etc.) were incorrectly classified as binary.Fix
Added a
KNOWN_TEXT_EXTENSIONSallowlist (50+ extensions) that short-circuits the HEAD request for recognized text file extensions. The detection strategy is now four-tiered:KNOWN_TEXT_EXTENSIONS→ text immediately (no network)BINARY_FILE_EXTENSIONS→ binary immediately (no network)Content-TypedecidesChanges
useIsBinaryFile.ts: AddedKNOWN_TEXT_EXTENSIONSset andisKnownTextExtensionhelper. Restructured hook to check text extensions before binary blocklist.useIsBinaryFile.test.ts: New test file with 10 tests covering JSONL, JSON, CSV, PY, YAML, MD, undefined path, PNG, ZIP, and unknown extensions.Summary by CodeRabbit
New Features
Tests