Skip to content

Fix relative paths for editor assets#2809

Open
cptbtptpbcptdtptp wants to merge 3 commits intogalacean:mainfrom
cptbtptpbcptdtptp:fix/load
Open

Fix relative paths for editor assets#2809
cptbtptpbcptdtptp wants to merge 3 commits intogalacean:mainfrom
cptbtptpbcptdtptp:fix/load

Conversation

@cptbtptpbcptdtptp
Copy link
Collaborator

@cptbtptpbcptdtptp cptbtptpbcptdtptp commented Sep 2, 2025

Please check if the PR fulfills these requirements

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

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

    • Fixes inconsistent remote asset loading by aligning cache lookups with a derived remote base URL, reducing mismatches when resolving relative item URLs.
  • Performance

    • Stabilizes and speeds asset loading through more consistent base-URL resolution and unified cache behavior.
  • Refactor

    • Internal loading logic reorganized to use a remoteAssetBaseURL; no public API or signature changes.
  • Documentation

    • No user-facing API changes; editor-managed imports behave more predictably.

@coderabbitai
Copy link

coderabbitai bot commented Sep 2, 2025

Walkthrough

ResourceManager's internal item-loading logic was changed to compute and use a derived remoteAssetBaseURL (from remoteConfig?.path ?? assetBaseURL) and to make it absolute against baseUrl when needed. Per-item inlined absolute URL resolution was removed; caching and loader lookups now use the derived base URL. Public APIs and exported signatures are unchanged.

Changes

Cohort / File(s) Summary
Remote base URL and loader/cache alignment
packages/core/src/asset/ResourceManager.ts
Removed per-item absolute URL resolution in _loadSingleItem. Introduced remoteAssetBaseURL = remoteConfig?.path ?? assetBaseURL, made absolute against baseUrl when required. Cache lookup, _assetUrlPool keys, and loader invocation now use remoteAssetBaseURL for resolving remoteAssetURL. No changes to public APIs or exported signatures.

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

I hop through paths both near and far,
I stitch a base where relative parts are,
I cache a crumb, resolve with care,
Fetching treasures from the open air. 🥕


📜 Recent 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.

📥 Commits

Reviewing files that changed from the base of the PR and between 5ec0ab8 and 8e039b0.

📒 Files selected for processing (1)
  • packages/core/src/asset/ResourceManager.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/core/src/asset/ResourceManager.ts
⏰ 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)
  • GitHub Check: e2e (22.x)
  • GitHub Check: codecov
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@cptbtptpbcptdtptp cptbtptpbcptdtptp changed the title Fixed relative paths for editor assets Fix relative paths for editor assets Sep 2, 2025
@cptbtptpbcptdtptp cptbtptpbcptdtptp self-assigned this Sep 2, 2025
@cptbtptpbcptdtptp cptbtptpbcptdtptp added the bug Something isn't working label Sep 2, 2025
@codecov
Copy link

codecov bot commented Sep 2, 2025

Codecov Report

❌ Patch coverage is 60.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.23%. Comparing base (a284963) to head (8e039b0).

Files with missing lines Patch % Lines
packages/core/src/asset/ResourceManager.ts 60.00% 2 Missing ⚠️
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              
Flag Coverage Δ
unittests 79.23% <60.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 only urls is provided.
  • Keep current behavior but guard urls access; 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.

📥 Commits

Reviewing files that changed from the base of the PR and between a284963 and 6086cad.

📒 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 _resolveRemoteUrl and _onSubAssetSuccess/_getRemoteUrl are aligned per above, cache/lookups will be consistent across editor/relative paths.


414-414: LGTM on subpackage derivation.

Using editorResourceItem?.subpackageName preserves editor metadata without altering public API.

Comment on lines 353 to 360
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;
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix absolute/base64 detection and normalize editor paths; also route all callers through the resolver.

  • Bug: Utils.isAbsoluteUrl is 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 _getRemoteUrl and _onSubAssetSuccess to 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.

Suggested change
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.

@cptbtptpbcptdtptp
Copy link
Collaborator Author

"files": [
    {
      "md5": "3d028bd4548c6c524ab7aa1cfbdac2fb",
      "id": "0000200",
      "type": "Material",
      "virtualPath": "/Internal/Material/DefaultMat",
      "path": "/octopus/Internal/Material/DefaultMat"
    },
    {
      "md5": "e81c1d8657a3ed6c9640691dc073676c",
      "id": "0000201",
      "type": "Material",
      "virtualPath": "/Internal/Material/SkyMat",
      "path": "/octopus/Internal/Material/SkyMat"
    },
    {
      "md5": "b3c3e29dc7dae7cdffa72d717ae41aca",
      "id": "0000202",
      "type": "Material",
      "virtualPath": "/Internal/Material/ParticleMat",
      "path": "/octopus/Internal/Material/ParticleMat"
    }
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant