-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes issues with packaged asset resolution #10621
Conversation
Please note, I've labeled this as, strictly speaking, this will change the contract of |
bc37366
to
41a3c9a
Compare
} | ||
|
||
function getScriptURL(): ?string { | ||
if (_scriptURL === undefined) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't see where _scriptURL comes from, but under which conditions would it be undefined? note that for image urls we support several non x-plat schemes apart from http/https, like ms-appx, ms-resource, resource, and some others; want to make sure this doesn't force these urls to be only "http/https" or "file" schemed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's just memoizing a result.
This change should be independent of the actual bundle root path, whether it's ms-appx://
, ms-resource://
or C:\...
for unpackaged apps.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is where the memoization variable is declared: https://github.com/microsoft/react-native-windows/pull/10621/files/41a3c9a59bf619cbd37e6eae96c607cea1ef4552#diff-7ef60247116c017061f149892f29f5977c15debf02f5bac3038ba60e7c85b99aR22
if (/*packager_assert && */ ris.uri.find("file://") == 0) { | ||
ris.uri.replace(0, 7, ris.bundleRootPath); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the idea is that if you say file://foo.png, this turns into ms-appx:///Assets/Bundle/foo.png
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, but now with the change to Image.resolveAssetSource
, the URI will already come in as ms-appx:///Assets/Bundle/foo.png
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you are truly consuming a bundled asset in React Native, you should do so by using:
<Image source={require('foo.png')} />
Rather than relying on an obscure implementation detail like:
<Image source={{uri: 'file://foo.png'}} />
So, this is another surface that is a "breaking change", but to be fair, whoever was depending on this implementation detail that they should not have been depending on it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure whether our internal partners are aware of this / using the right format, TBH. @stmoy FYI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, scratch that, using file://asset would never work because the resolved asset source would not include the internal '__packager_asset' flag, so this probably isn't breaking on that front.
It would only affect callsites where you use Image.resolveAssetPath and pass the result to some custom module or view manager that does not do proper validation on the URI (assumes that URIs will start with file://).
We needed zero code changes in Messenger when taking in this change. We were however able to delete a bunch of code for custom URI resolution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, scratch that, using file://asset would never work because the resolved asset source would not include the internal '__packager_asset' flag, so this probably isn't breaking on that front.
It would only affect callsites where you use Image.resolveAssetPath and pass the result to some custom module or view manager that does not do proper validation on the URI (assumes that URIs will start with file://).
We needed zero code changes in Messenger when taking in this change. We were however able to delete a bunch of code for custom URI resolution.
Summary: `Image.resolveAssetSource` has two different code paths - one for resolving assets from the packager server when running in standard debug builds and one for resolving assets when the JS package is pre-bundled. Previously, we were not providing the bundle root path to the `SourceCodeModule` for pre-bundled apps, and it was up to each individual native module and view manager that depends on resolving asset paths with `Image.resolveAssetSource` to replace `file://` with the bundle root path pulled from the InstanceSettingsSnapshot. Even after fixing the issue with `SourceCodeModule`, there is still one more issue for unpackaged apps, whose asset paths may be Windows file paths (e.g., `C:\...`) rather than packaged asset paths (e.g., `ms-appx://`). This change ensures that SourceCodeModule provides the bundle root path as the `scriptURL` constant and patches the bug in the upstream `resolveAssetSource` module to skip coersion of the bundle root path to a form like `file://`. Resolves microsoft#10620 Test Plan: See test plan in D39735423 Reviewers: lyahdav, shawndempsey, chpurrer, mcenk, jacke, helenistic, mowang Reviewed By: mowang Differential Revision: https://phabricator.intern.facebook.com/D39732643 Tasks: T132565343, T131482365
@rozele, looks like this PR breaks one of the integration tests.
|
Summary: `Image.resolveAssetSource` has two different code paths - one for resolving assets from the packager server when running in standard debug builds and one for resolving assets when the JS package is pre-bundled. Previously, we were not providing the bundle root path to the `SourceCodeModule` for pre-bundled apps, and it was up to each individual native module and view manager that depends on resolving asset paths with `Image.resolveAssetSource` to replace `file://` with the bundle root path pulled from the InstanceSettingsSnapshot. Even after fixing the issue with `SourceCodeModule`, there is still one more issue for unpackaged apps, whose asset paths may be Windows file paths (e.g., `C:\...`) rather than packaged asset paths (e.g., `ms-appx://`). This change ensures that SourceCodeModule provides the bundle root path as the `scriptURL` constant and patches the bug in the upstream `resolveAssetSource` module to skip coersion of the bundle root path to a form like `file://`. Resolves microsoft#10620 Test Plan: See test plan in D43159275 Reviewers: shawndempsey, chpurrer, lefever, helenistic Reviewed By: chpurrer Differential Revision: https://phabricator.intern.facebook.com/D43158676 Tasks: T140424672
Summary: Prior to PR microsoft#10621, the ImageViewManager for Paper and ImageViewComponent for Fabric required a workaround where file:// URIs were remapped to an absolute path using the InstanceSettings from the ReactContext. After microsoft#10621, the URI is already fully resolved by the time it reaches the native renderer for Image, so we do not need to do any URI rewrites. Test Plan: Images still load in RNTester: {F868525679} Reviewers: shawndempsey, helenistic, chpurrer, lefever Reviewed By: chpurrer Differential Revision: https://phabricator.intern.facebook.com/D43159275 Tasks: T140424672
Waiting on merge conflict resolution and integration test to pass. |
Thanks @chiaramooney - I'll rebase and take another look at the failing integration test. |
75781e5
to
8950402
Compare
@chiaramooney I think all the tests should pass now. The latest failure looks like a flaky build issue. |
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
@chiaramooney I've had terrible luck running the integration tests locally, not sure how to fix this. |
@rozele Would you mind rebasing off main one more time? Just to see if that will help :) |
Summary: `Image.resolveAssetSource` has two different code paths - one for resolving assets from the packager server when running in standard debug builds and one for resolving assets when the JS package is pre-bundled. Previously, we were not providing the bundle root path to the `SourceCodeModule` for pre-bundled apps, and it was up to each individual native module and view manager that depends on resolving asset paths with `Image.resolveAssetSource` to replace `file://` with the bundle root path pulled from the InstanceSettingsSnapshot. Even after fixing the issue with `SourceCodeModule`, there is still one more issue for unpackaged apps, whose asset paths may be Windows file paths (e.g., `C:\...`) rather than packaged asset paths (e.g., `ms-appx://`). This change ensures that SourceCodeModule provides the bundle root path as the `scriptURL` constant and patches the bug in the upstream `resolveAssetSource` module to skip coersion of the bundle root path to a form like `file://`. Resolves microsoft#10620 Test Plan: See test plan in D43159275 Reviewers: shawndempsey, chpurrer, lefever, helenistic Reviewed By: chpurrer Differential Revision: https://phabricator.intern.facebook.com/D43158676 Tasks: T140424672
Summary: `Image.resolveAssetSource` has two different code paths - one for resolving assets from the packager server when running in standard debug builds and one for resolving assets when the JS package is pre-bundled. Previously, we were not providing the bundle root path to the `SourceCodeModule` for pre-bundled apps, and it was up to each individual native module and view manager that depends on resolving asset paths with `Image.resolveAssetSource` to replace `file://` with the bundle root path pulled from the InstanceSettingsSnapshot. Even after fixing the issue with `SourceCodeModule`, there is still one more issue for unpackaged apps, whose asset paths may be Windows file paths (e.g., `C:\...`) rather than packaged asset paths (e.g., `ms-appx://`). This change ensures that SourceCodeModule provides the bundle root path as the `scriptURL` constant and patches the bug in the upstream `resolveAssetSource` module to skip coersion of the bundle root path to a form like `file://`. Resolves microsoft#10620 Test Plan: See test plan in D43159275 Reviewers: shawndempsey, chpurrer, lefever, helenistic Reviewed By: chpurrer Differential Revision: https://phabricator.intern.facebook.com/D43158676 Tasks: T140424672
Rebased :) |
`Image.resolveAssetSource` has two different code paths - one for resolving assets from the packager server when running in standard debug builds and one for resolving assets when the JS package is pre-bundled. Previously, we were not providing the bundle root path to the `SourceCodeModule` for pre-bundled apps, and it was up to each individual native module and view manager that depends on resolving asset paths with `Image.resolveAssetSource` to replace `file://` with the bundle root path pulled from the InstanceSettingsSnapshot. Even after fixing the issue with `SourceCodeModule`, there is still one more issue for unpackaged apps, whose asset paths may be Windows file paths (e.g., `C:\...`) rather than packaged asset paths (e.g., `ms-appx://`). This change ensures that SourceCodeModule provides the bundle root path as the `scriptURL` constant and patches the bug in the upstream `resolveAssetSource` module to skip coersion of the bundle root path to a form like `file://`. Resolves microsoft#10620
* Fixes issues with packaged asset resolution `Image.resolveAssetSource` has two different code paths - one for resolving assets from the packager server when running in standard debug builds and one for resolving assets when the JS package is pre-bundled. Previously, we were not providing the bundle root path to the `SourceCodeModule` for pre-bundled apps, and it was up to each individual native module and view manager that depends on resolving asset paths with `Image.resolveAssetSource` to replace `file://` with the bundle root path pulled from the InstanceSettingsSnapshot. Even after fixing the issue with `SourceCodeModule`, there is still one more issue for unpackaged apps, whose asset paths may be Windows file paths (e.g., `C:\...`) rather than packaged asset paths (e.g., `ms-appx://`). This change ensures that SourceCodeModule provides the bundle root path as the `scriptURL` constant and patches the bug in the upstream `resolveAssetSource` module to skip coersion of the bundle root path to a form like `file://`. Resolves microsoft#10620 * Change files
Description
Type of Change
Erase all that don't apply.
Why
Image.resolveAssetSource
has two different code paths - one for resolving assets from the packager server when running in standard debug builds and one for resolving assets when the JS package is pre-bundled.Previously, we were not providing the bundle root path to the
SourceCodeModule
for pre-bundled apps, and it was up to each individual native module and view manager that depends on resolving asset paths withImage.resolveAssetSource
to replacefile://
with the bundle root path pulled from the InstanceSettingsSnapshot.Even after fixing the issue with
SourceCodeModule
, there is still one more issue for unpackaged apps, whose asset paths may be Windows file paths (e.g.,C:\...
) rather than packaged asset paths (e.g.,ms-appx://
).Resolves #10620
What
This change ensures that SourceCodeModule provides the bundle root path as the
scriptURL
constant and patches the bug in the upstreamresolveAssetSource
module to skip coersion of the bundle root path to a form likefile://
.Please note, this is technically a "breaking change", any 3rd party native modules or view managers that leveraged
Image.resolveAssetSource
assuming it would return afile://
path with a relative asset path will now see that the path is already fully qualified with the bundle root path.Testing
Created bundled version of Playground, ran RNTester, and confirmed packaged image assets still resolve correctly (in this case, the thumbs up image is a package asset):
Microsoft Reviewers: Open in CodeFlow