react-native-windows icon indicating copy to clipboard operation
react-native-windows copied to clipboard

Fixes issues with packaged asset resolution

Open rozele opened this issue 1 year ago • 1 comments

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):

image

Microsoft Reviewers: Open in CodeFlow

rozele avatar Sep 22 '22 14:09 rozele

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 avatar Sep 22 '22 15:09 rozele

@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

acoates-ms avatar Jan 27 '23 16:01 acoates-ms

Waiting on merge conflict resolution and integration test to pass.

chiaramooney avatar Mar 29 '23 21:03 chiaramooney

Thanks @chiaramooney - I'll rebase and take another look at the failing integration test.

rozele avatar Apr 02 '23 21:04 rozele

@chiaramooney I think all the tests should pass now. The latest failure looks like a flaky build issue.

rozele avatar Jun 02 '23 14:06 rozele

/azp run

chiaramooney avatar Jun 07 '23 20:06 chiaramooney

Azure Pipelines successfully started running 1 pipeline(s).

azure-pipelines[bot] avatar Jun 07 '23 20:06 azure-pipelines[bot]

/azp run

chiaramooney avatar Jul 05 '23 22:07 chiaramooney

Azure Pipelines successfully started running 1 pipeline(s).

azure-pipelines[bot] avatar Jul 05 '23 22:07 azure-pipelines[bot]

@chiaramooney I've had terrible luck running the integration tests locally, not sure how to fix this.

rozele avatar Jul 17 '23 01:07 rozele

@rozele Would you mind rebasing off main one more time? Just to see if that will help :)

TatianaKapos avatar Jul 17 '23 20:07 TatianaKapos

@rozele Would you mind rebasing off main one more time? Just to see if that will help :)

Rebased :)

rozele avatar Oct 10 '23 14:10 rozele