Fix relative paths for editor assets#2809
Fix relative paths for editor assets#2809cptbtptpbcptdtptp wants to merge 3 commits intogalacean:mainfrom
Conversation
WalkthroughResourceManager's internal item-loading logic was changed to compute and use a derived Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor App
participant RM as ResourceManager
participant Loader
participant Cache
participant Net as Network
App->>RM: load(requestPath, options)
RM->>RM: compute remoteAssetBaseURL = remoteConfig?.path ?? assetBaseURL
alt remoteAssetBaseURL not absolute and baseUrl present
RM->>RM: remoteAssetBaseURL = resolveAbsolute(baseUrl, remoteAssetBaseURL)
end
RM->>Cache: check(remoteAssetBaseURL + queryPath)
alt cache hit
Cache-->>RM: cached asset
RM-->>App: return asset
else cache miss
RM->>Loader: load(remoteAssetBaseURL + queryPath, inferred type)
Loader->>Net: fetch(...)
Net-->>Loader: data
Loader-->>RM: asset
RM->>Cache: store(asset, remoteAssetBaseURL + queryPath)
RM-->>App: return asset
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 💡 Knowledge Base configuration:
You can enable these sources in your CodeRabbit configuration. 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
✨ Finishing Touches
🧪 Generate 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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2809 +/- ##
==========================================
- Coverage 79.23% 79.23% -0.01%
==========================================
Files 846 846
Lines 90233 90233
Branches 8951 8951
==========================================
- Hits 71500 71498 -2
- Misses 18592 18594 +2
Partials 141 141
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/core/src/asset/ResourceManager.ts (1)
341-351: Don’t read assetInfo.url before it’s set; support urls[] and throw Error, not string.
_getTypeByUrl(assetInfo.url)can crash when onlyurlsis provided.- Keep current behavior but guard
urlsaccess; improve error.Apply:
@@ - private _assignDefaultOptions(assetInfo: LoadItem, editorResourceItem?: EditorResourceItem): LoadItem { - assetInfo.type = assetInfo.type ?? editorResourceItem?.type ?? ResourceManager._getTypeByUrl(assetInfo.url); + private _assignDefaultOptions(assetInfo: LoadItem, editorResourceItem?: EditorResourceItem): LoadItem { + const candidateUrl = assetInfo.url ?? assetInfo.urls?.[0]; + assetInfo.type = + assetInfo.type ?? editorResourceItem?.type ?? (candidateUrl ? ResourceManager._getTypeByUrl(candidateUrl) : undefined); if (assetInfo.type === undefined) { - throw `asset type should be specified: ${assetInfo.url}`; + throw new Error(`asset type should be specified: ${candidateUrl ?? "(unknown url)"}`); } assetInfo.retryCount = assetInfo.retryCount ?? this.retryCount; assetInfo.timeout = assetInfo.timeout ?? this.timeout; assetInfo.retryInterval = assetInfo.retryInterval ?? this.retryInterval; - assetInfo.url = assetInfo.url ?? assetInfo.urls.join(","); + assetInfo.url = assetInfo.url ?? (assetInfo.urls ? assetInfo.urls.join(",") : candidateUrl); return assetInfo; }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
packages/core/src/asset/ResourceManager.ts(3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/core/src/asset/ResourceManager.ts (2)
packages/core/src/asset/LoadItem.ts (1)
LoadItem(8-38)packages/core/src/Utils.ts (1)
Utils(3-269)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: build (22.x, windows-latest)
- GitHub Check: codecov
- GitHub Check: e2e (22.x)
🔇 Additional comments (2)
packages/core/src/asset/ResourceManager.ts (2)
373-373: Centralized URL resolution is the right direction.Once
_resolveRemoteUrland_onSubAssetSuccess/_getRemoteUrlare aligned per above, cache/lookups will be consistent across editor/relative paths.
414-414: LGTM on subpackage derivation.Using
editorResourceItem?.subpackageNamepreserves editor metadata without altering public API.
| private _resolveRemoteUrl(url: string, editorResourceItem?: EditorResourceItem): string { | ||
| if (Utils.isAbsoluteUrl) return url; | ||
| if (editorResourceItem) { | ||
| return this.baseUrl ? Utils.resolveAbsoluteUrl(this.baseUrl, "." + url) : url; | ||
| } else { | ||
| return this.baseUrl ? Utils.resolveAbsoluteUrl(this.baseUrl, url) : url; | ||
| } | ||
| } |
There was a problem hiding this comment.
Fix absolute/base64 detection and normalize editor paths; also route all callers through the resolver.
- Bug:
Utils.isAbsoluteUrlis not invoked; it always truthy-returns, breaking relative path handling. - Handle
data:URLs. - Only prepend
./when the incoming editor path begins with/. - Use the same resolver in
_getRemoteUrland_onSubAssetSuccessto keep cache/loading keys consistent.
Apply:
@@
- private _resolveRemoteUrl(url: string, editorResourceItem?: EditorResourceItem): string {
- if (Utils.isAbsoluteUrl) return url;
- if (editorResourceItem) {
- return this.baseUrl ? Utils.resolveAbsoluteUrl(this.baseUrl, "." + url) : url;
- } else {
- return this.baseUrl ? Utils.resolveAbsoluteUrl(this.baseUrl, url) : url;
- }
- }
+ private _resolveRemoteUrl(url: string, editorResourceItem?: EditorResourceItem): string {
+ if (Utils.isAbsoluteUrl(url) || Utils.isBase64Url(url)) return url;
+ const candidate = editorResourceItem && url.startsWith("/") ? `.${url}` : url;
+ return this.baseUrl ? Utils.resolveAbsoluteUrl(this.baseUrl, candidate) : candidate;
+ }And ensure all call sites funnel through it:
@@
_getRemoteUrl(url: string): string {
- return this._virtualPathResourceMap[url]?.path ?? url;
+ const editorResourceItem = this._virtualPathResourceMap[url];
+ return this._resolveRemoteUrl(editorResourceItem?.path ?? url, editorResourceItem);
}
@@
_onSubAssetSuccess<T>(assetBaseURL: string, assetSubPath: string, value: T): void {
- const remoteAssetBaseURL = this._virtualPathResourceMap[assetBaseURL]?.path ?? assetBaseURL;
+ const editorResourceItem = this._virtualPathResourceMap[assetBaseURL];
+ const remoteAssetBaseURL = this._resolveRemoteUrl(editorResourceItem?.path ?? assetBaseURL, editorResourceItem);📝 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.
| private _resolveRemoteUrl(url: string, editorResourceItem?: EditorResourceItem): string { | |
| if (Utils.isAbsoluteUrl) return url; | |
| if (editorResourceItem) { | |
| return this.baseUrl ? Utils.resolveAbsoluteUrl(this.baseUrl, "." + url) : url; | |
| } else { | |
| return this.baseUrl ? Utils.resolveAbsoluteUrl(this.baseUrl, url) : url; | |
| } | |
| } | |
| ++ b/packages/core/src/asset/ResourceManager.ts | |
| @@ -350,12 +350,9 @@ export class ResourceManager { | |
| - private _resolveRemoteUrl(url: string, editorResourceItem?: EditorResourceItem): string { | |
| - if (Utils.isAbsoluteUrl) return url; | |
| - if (editorResourceItem) { | |
| - return this.baseUrl ? Utils.resolveAbsoluteUrl(this.baseUrl, "." + url) : url; | |
| - } else { | |
| - return this.baseUrl ? Utils.resolveAbsoluteUrl(this.baseUrl, url) : url; | |
| - } | |
| private _resolveRemoteUrl(url: string, editorResourceItem?: EditorResourceItem): string { | |
| if (Utils.isAbsoluteUrl(url) || Utils.isBase64Url(url)) return url; | |
| const candidate = editorResourceItem && url.startsWith("/") ? `.${url}` : url; | |
| return this.baseUrl ? Utils.resolveAbsoluteUrl(this.baseUrl, candidate) : candidate; | |
| } | |
| _getRemoteUrl(url: string): string { | |
| const editorResourceItem = this._virtualPathResourceMap[url]; | |
| return this._resolveRemoteUrl(editorResourceItem?.path ?? url, editorResourceItem); | |
| } | |
| _onSubAssetSuccess<T>(assetBaseURL: string, assetSubPath: string, value: T): void { | |
| const editorResourceItem = this._virtualPathResourceMap[assetBaseURL]; | |
| const remoteAssetBaseURL = this._resolveRemoteUrl(editorResourceItem?.path ?? assetBaseURL, editorResourceItem); | |
| // …rest of method remains unchanged… | |
| } |
🤖 Prompt for AI Agents
In packages/core/src/asset/ResourceManager.ts around lines 353-360, the resolver
currently uses Utils.isAbsoluteUrl without invoking it, doesn't treat data: URLs
as absolute, and always prepends "./" for editor items; fix by calling
Utils.isAbsoluteUrl(url) and treating any URL starting with "data:" as absolute
so those return unchanged, only prepend "./" when editorResourceItem is present
AND the incoming url begins with "/", otherwise leave the path as-is, and ensure
_getRemoteUrl and _onSubAssetSuccess are updated to call this single
_resolveRemoteUrl so cache/loading keys remain consistent across callers.
|
Please check if the PR fulfills these requirements
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
What is the current behavior? (You can also link to an open issue here)
What is the new behavior (if this is a feature change)?
Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)
Other information:
Summary by CodeRabbit
Bug Fixes
Performance
Refactor
Documentation