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>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthrough
ChangesSynchronous binary-file detection
Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ 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
|
…end always returns application/octet-stream Signed-off-by: mschwab <mschwab@nvidia.com>
Signed-off-by: mschwab <mschwab@nvidia.com>
…ilePath Signed-off-by: mschwab <mschwab@nvidia.com>
Signed-off-by: mschwab <mschwab@nvidia.com>
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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`:
- Around line 32-35: The test named for .yaml and .yml only exercises
useIsBinaryFile with config.yaml, so the .yml allowlist path is unverified;
update the useIsBinaryFile test case to also invoke the hook with a .yml
filename and assert the same { isBinary: false, isLoading: false } result,
keeping the existing yaml check so both extensions are covered.
In `@web/packages/studio/src/components/filesets/hooks/useIsBinaryFile.ts`:
- Around line 18-30: The useIsBinaryFile hook is now failing open for every
unknown extension, which lets non-text files reach preview paths. Keep the
existing fast checks in useIsBinaryFile, but change the fallback for
unrecognized filePath values to perform a real binary detection instead of
returning false; use the existing isKnownTextExtension and isBinaryExtension
helpers as the named entry points to update, and ensure unknown extensions do
not default to text.
🪄 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: 8e5dad57-33da-4ebe-8302-d885dd6eebfa
📒 Files selected for processing (4)
web/packages/studio/src/components/FilesetFilePreviewPanel/FilesetFilePreviewContent/index.tsxweb/packages/studio/src/components/filesets/hooks/useIsBinaryFile.test.tsweb/packages/studio/src/components/filesets/hooks/useIsBinaryFile.tsweb/packages/studio/src/constants/constants.ts
…yFile Signed-off-by: mschwab <mschwab@nvidia.com>
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
.json,.csv,.py,.yaml,.md) without server requests.isLoadingis no longer used, and unknown extensions default to non-binary.KNOWN_TEXT_EXTENSIONSconstant.