Direct FileDef instance fetching in render-store context#4033
Direct FileDef instance fetching in render-store context#4033
Conversation
There was a problem hiding this comment.
Pull request overview
This PR enables the render-store to fetch FileDef instances directly when a card references files that haven't been indexed yet, bypassing the need to wait for indexing. It also refactors shared utilities to improve code reuse.
Changes:
- Extracts
resolveFileDefCodeReffunction toruntime-common/file-def-code-ref.tsfor reuse across index runner, file-extract route, and store service - Extracts
FileDefAttributesExtractorclass tohost/app/utils/file-def-attributes-extractor.tsfor reuse across file-extract route and store service - Adds
extractFileMetaDirectlymethod in store service that fetches raw file bytes and runsextractAttributeson the fly during render context
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| packages/runtime-common/index.ts | Exports the new file-def-code-ref module |
| packages/runtime-common/file-def-code-ref.ts | New file containing extracted resolveFileDefCodeRef function and file extension mappings |
| packages/runtime-common/index-runner.ts | Updated to import and use extracted resolveFileDefCodeRef function and baseFileRef constant |
| packages/host/app/utils/file-def-attributes-extractor.ts | New file containing extracted FileDefAttributesExtractor class and helper functions |
| packages/host/app/routes/render/file-extract.ts | Simplified by importing and using extracted FileDefAttributesExtractor class |
| packages/host/app/services/store.ts | Adds extractFileMetaDirectly method to fetch FileDef instances directly when in render context |
| packages/realm-server/tests/card-endpoints-test.ts | Modified test to write images to disk before indexing to exercise the new direct fetch path |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Preview deployments |
Host Test Results 1 files ± 0 1 suites ±0 3h 25m 49s ⏱️ + 1h 41m 36s For more details on these errors, see this check. Results for commit 21ad360. ± Comparison against base commit 82e0e25. ♻️ This comment has been updated with latest results. |
d232de1 to
b70c5e6
Compare
When prerendering a card that references files (e.g., images via linksTo(FileDef)), the render store now bypasses the index and fetches file bytes directly from the realm server, running extractAttributes on the fly. This ensures subclass-specific attributes (width/height for images, title/content for markdown) are available even when the referenced file hasn't been indexed yet. - Extract resolveFileDefCodeRef to shared runtime-common module - Extract FileDefAttributesExtractor to shared host utility - Add extractFileMetaDirectly render-store path in getFileMetaInstance - Update test to exercise card-before-file indexing order Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
b70c5e6 to
21ad360
Compare
Summary
extractAttributeson the fly to produce full subclass attributes (width/height for images, title/content for markdown)resolveFileDefCodeReftoruntime-common/file-def-code-ref.tsandFileDefAttributesExtractortohost/app/utils/file-def-attributes-extractor.tsfor reuse across the index runner, file-extract route, and store serviceTest plan
'includes FileDef resources for file links in included payload'test to write images to disk before indexing the card, exercising theextractFileMetaDirectlypath where images are on disk but not yet indexed during card prerenderingFileDefAttributesExtractor)resolveFileDefCodeRefextraction)🤖 Generated with Claude Code