Skip to content

fix: use file parameter instead of getActiveFile() for embed processing#123

Merged
bingryan merged 1 commit intomasterfrom
bingryan/atlanta
Jan 6, 2026
Merged

fix: use file parameter instead of getActiveFile() for embed processing#123
bingryan merged 1 commit intomasterfrom
bingryan/atlanta

Conversation

@bingryan
Copy link
Copy Markdown
Owner

@bingryan bingryan commented Jan 6, 2026

Summary

Problem

When exporting large documents with multiple embedded files (e.g., ~88,000 chars), some embeds weren't being included. The issue occurred because:

  1. getActiveFile() could return undefined in some scenarios
  2. During batch exports or async processing, the active file might change
  3. This led to inconsistent behavior - different embeds would be missed on each export

Solution

  • Use file.path (the function parameter) instead of cfile.path from getActiveFile()
  • The file parameter is the actual file being exported, so it's always correct
  • Removed the if (cfile != undefined) check since file.path is always available

Test plan

  • Export a single file with multiple embeds
  • Export large documents (50k+ chars) with embeds
  • Batch export multiple files with embeds
  • Verify HTML export shows content instead of "undefined"

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Fixed embed resolution during file export to correctly use the file being exported instead of relying on the active editor file, ensuring embeds are properly resolved and replaced regardless of which file is currently open.

✏️ Tip: You can customize this high-level summary in your review settings.

Fixes #95 where embedded markdown files were being missed when dealing
with large documents. The previous code used `getActiveFile()` which
could return undefined or the wrong file during async processing,
especially in batch export scenarios.

Now uses the `file.path` parameter which is the correct file being
exported, ensuring consistent behavior regardless of active file state.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jan 6, 2026

📝 Walkthrough

Walkthrough

The embed processing logic in src/utils.ts now resolves embeds using the explicit file path (file.path) being exported instead of relying on the editor's active file state, ensuring consistent embed resolution regardless of active editor context changes during export.

Changes

Cohort / File(s) Summary
Embed Path Resolution
src/utils.ts
Changed embed processing to reference the file path being exported (file.path) instead of the active editor file (getActiveFile), ensuring embed lookups, parsing, and block-content extraction operate on a guaranteed file path independent of dynamic editor state

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 Embeds once whispered to the active file's whim,
Now they follow the path, steady and trim!
No more vanishing acts when the editor shifts,
The export now catches each embedded gift! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: replacing getActiveFile() with the file parameter for embed processing, which directly addresses the core fix.
Linked Issues check ✅ Passed The PR directly addresses issue #95 by replacing getActiveFile() with file.path for embed processing, ensuring consistent embed inclusion during exports and resolving 'undefined' rendering in HTML exports.
Out of Scope Changes check ✅ Passed All changes are scoped to embed processing in the export routine and directly support the stated objective of fixing inconsistent embed omission during exports.
✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c6259fb and 80ed55f.

📒 Files selected for processing (1)
  • src/utils.ts
🔇 Additional comments (1)
src/utils.ts (1)

935-967: Excellent fix for the embed processing issue.

The changes correctly address the root cause of intermittent missing embeds by using the explicit file.path parameter instead of relying on getActiveFile(). This ensures:

  1. Consistent embed resolution - The file being exported is always known, regardless of active editor state
  2. Async safety - No race conditions when the active file changes during async processing
  3. Batch export reliability - Each file in a batch uses its own path for embed resolution
  4. HTML export fix - The guard on line 964 prevents "undefined" from appearing in HTML output

The implementation is correct: file.path is used consistently in both getEmbedMap() (line 937) and parseEmbedLink() (line 948), and the undefined check on line 964 properly prevents invalid replacements. No other problematic uses of getActiveFile() exist in the export context.


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 and usage tips.

@bingryan bingryan merged commit 483f5a6 into master Jan 6, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Embedded MD files seem to get missed when dealing with a large document - both to MD and to HTML - Undefined?

1 participant