Skip to content

fix: preview recognized source files served as octet-stream - #3232

Open
Creatixpy wants to merge 1 commit into
npmx-dev:mainfrom
Creatixpy:fix/code-preview-octet-stream
Open

fix: preview recognized source files served as octet-stream#3232
Creatixpy wants to merge 1 commit into
npmx-dev:mainfrom
Creatixpy:fix/code-preview-octet-stream

Conversation

@Creatixpy

Copy link
Copy Markdown

🔗 Linked issue

Fixes #2721

🧭 Context

The code viewer hides recognized source files when jsDelivr serves them as application/octet-stream. Reproduced with astro-icon@1.1.5/components/Icon.astro: the API already detects Astro and highlights all 138 lines, but the page shows “Binary file”.

📚 Description

Use the existing detected language to allow previews for generic octet-stream responses. Unknown files (text, the language fallback) and specific binary MIME types retain their warning. This follows the approach suggested in the issue without duplicating the extension map.

Also recognize the text bun.lock format as JSONC. bun.lockb stays unknown/binary. Bump the file-response cache version so previously cached Bun lockfiles receive the new language classification.

Validation:

  • The new regressions fail on the original code (5 failures); all 32 targeted tests pass with the fix.
  • Full test run: 1,790 unit tests passed across 85 files. Nuxt component tests could not start because their Chromium session connection timed out, so the full command exited unsuccessfully.
  • pnpm test:types and pnpm vp run lint passed; commit hooks also passed.
  • Browser verification: Astro source renders with highlighting and line numbers; bun.lock@0.0.0/bun.lock renders its 28 lines. Both upstream responses still use application/octet-stream.

Before:

Astro source incorrectly hidden as binary

After:

Astro source displayed with syntax highlighting

Reviewed with the help of AI.

@agentscanapp

agentscanapp Bot commented Sep 7, 2026

Copy link
Copy Markdown

Thanks for opening this pull request! 🎉

We really appreciate you taking the time to contribute, @Creatixpy.

A maintainer will take a look as soon as they can. In the meantime, please make sure that:

  • the description explains what changed and why
  • any related issues are linked
  • existing tests still pass

If anything needs adjusting we'll leave comments here. Thanks again!

@vercel

vercel Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
npmx.dev Ready Ready Preview Sep 7, 2026 10:49pm UTC
2 Skipped Deployments
Project Deployment Actions Updated
docs.npmx.dev Ignored Ignored Preview Sep 7, 2026 10:49pm UTC
npmx-lunaria Ignored Ignored Sep 7, 2026 10:49pm UTC

Request Review

@coderabbitai

coderabbitai Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Team

Run ID: 2c5782c1-e927-4fea-884c-243d6c319db4

📥 Commits

Reviewing files that changed from the base of the PR and between fff9a6c and ecca1ab.

📒 Files selected for processing (6)
  • app/pages/package-code/[[org]]/[packageName]/v/[version]/[...filePath].vue
  • app/utils/file-types.ts
  • server/api/registry/file/[...pkg].get.ts
  • server/utils/code-highlight.ts
  • test/unit/file-types.spec.ts
  • test/unit/server/utils/code-highlight.spec.ts

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Summary

Summary by CodeRabbit

  • New Features

    • Bun lockfiles (bun.lock) are now recognised and displayed with JSONC syntax highlighting.
    • Source files served with a generic binary content type can now be correctly previewed when their language is recognised.
  • Bug Fixes

    • Genuine binary files, including archives, fonts, WebAssembly, and images, continue to be handled as binary content rather than displayed as text.

Walkthrough

Changes

The code browser now treats application/octet-stream files as text when a recognised language is detected. Binary MIME types remain binary. Cache keys use version 4. bun.lock files now use JSONC highlighting, while bun.lockb remains plain text.

Code preview handling

Layer / File(s) Summary
Language-aware binary detection
server/api/registry/file/[...pkg].get.ts, app/utils/file-types.ts, app/pages/package-code/.../[...filePath].vue, test/unit/file-types.spec.ts
Binary detection accepts the detected language. Recognised languages allow octet-stream content to be previewed. Tests cover recognised, missing, unknown, explicit binary, and text MIME types. Cache keys use version 4.
Bun lockfile highlighting
server/utils/code-highlight.ts, test/unit/server/utils/code-highlight.spec.ts
bun.lock maps to JSONC. bun.lockb remains mapped to plain text.

Suggested reviewers: jhroemer

Merge Risk: ⚪ Minimal · up to ecca1

Recognized source files served as octet-stream now render with syntax highlighting, while unknown and explicit binary files retain binary handling. Bun text lockfiles receive JSONC highlighting without changing bun.lockb fallback behavior, and no merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarises the main change: previewing recognised source files served as application/octet-stream.
Description check ✅ Passed The description directly explains the binary-detection fix, Bun lockfile support, cache update, and validation results.
Linked Issues check ✅ Passed The changes satisfy issue #2721 by allowing recognised plaintext source files, including Svelte and Astro files, to render with syntax highlighting instead of showing a binary warning. Binary MIME typ…
Out of Scope Changes check ✅ Passed The changes remain within the code-viewer file classification and preview scope. Bun lockfile recognition, related tests, and the cache version update support the same behaviour and are not unrelated …
✨ 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.

@codecov

codecov Bot commented Sep 7, 2026

Copy link
Copy Markdown

@gameroman gameroman added the needs review This PR is waiting for a review from a maintainer label Sep 7, 2026
@gameroman

Copy link
Copy Markdown
Member

Very nice!

@gameroman
gameroman requested a review from a team September 7, 2026 22:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs review This PR is waiting for a review from a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Code browser: preview detects various plaintext files as binary

2 participants