-
Notifications
You must be signed in to change notification settings - Fork 693
Use indexed watch folder paths for external assets - #1892
Draft
robhogan wants to merge 4 commits into
Draft
Conversation
@meta-cla
meta-cla
Bot
added
the
CLA Signed
This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
label
Aug 31, 2026
robhogan
force-pushed
the
robhogan/watch-folder-asset-urls
branch
2 times, most recently
from
September 7, 2026 13:17
2db7b1c to
8c7e66f
Compare
`_getAssetsFromDependencies` built asset URLs relative to `unstable_serverRoot`, while both readers of those URLs use `projectRoot`: the `/assets` endpoint resolves a bare relative path against `this._config.projectRoot`, and `[metro-project]` maps to `projectRoot` in `_sourceRequestRoutingMap`. With `unstable_serverRoot` set to a monorepo root, an in-project asset was served at a URL the endpoint then failed to resolve. That line dates to the original `unstable_serverRoot` change, which applied the server root broadly across `Server` and left the other asset call site on `projectRoot`. Anchor asset URLs on `projectRoot`, and route the `/assets` manifest endpoint through `_getAssetsFromDependencies` so all three callers share one options object and the root cannot drift again. Changelog: ``` - **[Fix]**: Asset URLs are relative to `projectRoot` rather than `server.unstable_serverRoot`, so they resolve at the `/assets` endpoint ```
robhogan
force-pushed
the
robhogan/watch-folder-asset-urls
branch
from
September 7, 2026 13:28
8c7e66f to
ec1b3fc
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
Summary
Assets outside
projectRootcurrently derive theirhttpServerLocationfrom a path relative toprojectRoot. This can produce..paths which escape/assets, and does not identify which configured watch folder owns the asset.This uses Metro's existing
[metro-watchFolders]/N/namespace for external asset URLs - the same namespace_sourceRequestRoutingMapalready serves source requests from, and which_resolveWatchFolderPrefixalready decodes:getAssetsencode the path relative to the containing watch folder/assetsendpoint resolves the watch folder prefix before selecting platform and density variantsprojectRootretain their existing URLsKeeping these requests under
/assetspreserves Metro's platform-specific and density-aware asset resolution.The URL path reaches the default transformer as a separate
TransformExtrasargument rather than as a field onJsTransformOptions, because those options are spread wholesale intoBabelTransformerArgsand this isn't something custom Babel transformers should be given. It's a named object rather than a bare positional argument so that the next Metro-computed input doesn't need a seventh parameter.The last commit is a related fix which stands on its own.
_getAssetsFromDependenciesbuilt asset URLs relative toserver.unstable_serverRoot, while both readers of those URLs useprojectRoot- the/assetsendpoint resolves a bare relative path againstthis._config.projectRoot, and[metro-project]maps toprojectRootin_sourceRequestRoutingMap. Withunstable_serverRootset to a monorepo root, an in-project asset was served at a URL the endpoint then failed to resolve. That line dates to the originalunstable_serverRootchange, which applied the server root broadly acrossServerand left the other asset call site onprojectRoot. All three callers now share one options object, so the root can't drift again.Fixes: #19
Fixes: #290
Fixes: #1614
Fixes: #1615
Changelog:
Test plan
Created a minimal project which imports an asset from a sibling watch folder:
index.jsimports the sibling asset:Started Metro from this checkout with
sharedconfigured as a watch folder:Requested an iOS bundle and inspected the generated asset metadata:
Metro normalises
projectRootas watch folder 0, so the configured sibling directory is watch folder 1.Requested the emitted asset path at 2x density for iOS:
The response body matches
tone@2x.ios.mp3, confirming that the indexed URL resolves through the sibling watch folder while retaining platform and density selection.New unit tests cover the two halves of that URL scheme meeting in the middle:
getAssetUrlPathcomposed with_resolveWatchFolderPrefixround-trips back to the original absolute path for in-project, nested and watch-folder assets, and_getAssetsFromDependenciesis pinned toprojectRootwithunstable_serverRootset. Both fail if the mapping is perturbed - an off-by-one in the watch folder index breaks the former, restoring_getServerRootDir()breaks the latter.Also ran:
All checks passed.