react-native-windows
react-native-windows copied to clipboard
Fixes issues with packaged asset resolution
Description
Type of Change
Erase all that don't apply.
- Bug fix (non-breaking change which fixes an issue)
- Breaking change (fix or feature that would cause existing functionality to not work as expected)
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 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://
).
Resolves #10620
What
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://
.
Please note, this is technically a "breaking change", any 3rd party native modules or view managers that leveraged Image.resolveAssetSource
assuming it would return a file://
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
Please note, I've labeled this as, strictly speaking, this will change the contract of Image.resolveAssetSource
, but assuming any 3rd party modules are doing appropriate URI validation, it's unlikely for anything to break.
@rozele, looks like this PR breaks one of the integration tests.
I think this one isn't loading the image correctly for some reason.
https://github.com/microsoft/react-native-windows/blob/f3475d428b20dfe719c79f753941fdb4e6aeac3a/packages/integration-test-app/tests/SampleTests.tsx#L33
Waiting on merge conflict resolution and integration test to pass.
Thanks @chiaramooney - I'll rebase and take another look at the failing integration test.
@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 :)
@rozele Would you mind rebasing off main one more time? Just to see if that will help :)
Rebased :)