question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. Itย collects links to all the places you might be looking at while hunting down a tough bug.

And, if youโ€™re still stuck at the end, weโ€™re happy to hop on a call to see how we can help out.

After upgrade, the assets in other watchedFolders are not resolved correctly

See original GitHub issue

Do you want to request a feature or report a bug?

A bug

What is the current behavior?

Images located in other watchedFolders are not resolved properly in react native after upgrade.

Upgrade details:

  • React Native 0.57.1 => 0.57.7
  • metro preset 0.45.3 => 0.49.2

The structure of my files looks like this:

 ๐Ÿ“‚ affiny
 โ”œ ๐Ÿ“‚ affiny-app
 โ”‚ โ”œ ๐Ÿ“‚ assets
 โ”‚ โ”‚ โ”” ๐Ÿ–ผ splashscreen.png
 โ”‚ โ”” ๐Ÿ“‚ src
 โ”‚   โ”” ๐Ÿ“„ app.specific.stuff.ts
 โ”œ ๐Ÿ“‚ affiny-web
 โ”‚ โ”œ ๐Ÿ“‚ assets
 โ”‚ โ”‚ โ”” ๐Ÿ–ผ web.specific.image.png
 โ”‚ โ”” ๐Ÿ“‚ src
 โ”‚   โ”” ๐Ÿ“„ web.specific.stuff.ts
 โ”” ๐Ÿ“‚ affny-core
   โ”œ ๐Ÿ“‚ assets
   โ”‚ โ”” ๐Ÿ–ผ not.specific.image.png
   โ””๐Ÿ“‚ src
     โ”” ๐Ÿ“„ not.specific.stuff.ts

and I have a rn-cli:

const path = require('path');

module.exports = {
  watchFolders: [
    path.resolve(__dirname, '../affiny-core'),
  ],
};

Before upgrade, i can do:

<Image src={require('affiny-app/assets/splashscreen.png')} />

and

<Image src={require('affiny-core/assets/not.specific.image.png')} />

After upgrade, i can do:

<Image src={require('affiny-app/assets/splashscreen.png')} />

but image in my-project-core, eg:

<Image src={require('affiny-core/assets/not.specific.image.png')} />

are resulting in a gray screen:

image

What is the expected behavior?

Either:

  • no regression, everything working as before.
  • a deprecation documented so I can adapt my code

Investigation

I added a breakpoint here:

image

Before the upgrade, the packager url for assets was:

resolver.defaultAsset().uri;
// -> "http://localhost:8081/assets/assets/img/profile_capture/search.jpg?platform=ios&hash=51dac229328bf5d045e9401cb6cb3cb4"

after the upgrade:

resolver.defaultAsset().uri;
// -> "http://localhost:8081/affiny-core/assets/img/profile_capture/search.jpg?platform=ios&hash=51dac229328bf5d045e9401cb6cb3cb4"

Note above:

  • โ€œaffiny-coreโ€ instead of โ€œassetsโ€

When asking for http://localhost:8081/affiny-core/assets/img/profile_capture/search.jpg?platform=ios&hash=51dac229328bf5d045e9401cb6cb3cb4, I get a 404.

Note that http://localhost:8081/assets/assets/img/profile_capture/search.jpg?platform=ios&hash=51dac229328bf5d045e9401cb6cb3cb4 works on both old RN/metro and new RN/metro.

Idea

Seems like https://github.com/facebook/metro/commit/ea980fd821abae27218dc1a4a3a0b9e454958bfd#diff-71293ea379a7cf006cd4648701a7c568 (https://github.com/facebook/metro/pull/299) is the root cause.

Maybe the RN packager is not aware of the public path.

Reproduction steps

I think it is a bit involving to do a repro here. Maybe you will have an idea with above investigation, else I will spend time doing a repro.

Configuration

Node: v8.11.3 React Native: 0.57.7 Metro: 0.49.2

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

11reactions
Kudocommented, Dec 10, 2018

In my case, to the watchFolder resides out of projectRoot. Even the metro server accepts the request like. http://localhost:8081/assets/../../../common/assets/images/image.png

The RN Android image system uses okhttp to send requests. okhttp seems to prune the request as http://localhost:8081/common/assets/images/image.png Letโ€™s why 404 happens.

My folder structure is pretty much like @tychota. Environment: RN 0.57.7, metro 0.48.3

Well, there is a dirty workaround for me. To create a symbolic link in current project root to the shared folder. ln -s ../../../common # In my project root This seems make metro able to find files even without 0eaa74182 patch.

2reactions
rafecacommented, Nov 30, 2018

Ok, Iโ€™ve been able to reproduce it, the issue was introduced in https://github.com/facebook/metro/commit/a711d73c1ce7c1ed0bc3393b8842b7621e6d3e69 ๐Ÿ˜…

Thanks for the detailed explanation of the issue, it was very helpful to debug it ๐Ÿ˜ƒ

Very soon we want to force all watch folders to be inside the project root of metro, this way Metro can safely use the project root as the root of the http server that provides the assets and this will fix this issue.

In order to make this change, weโ€™ll change the meaning of the projectRoot, which will just be a common folder where all the different watchFolders reside (so itโ€™s going to be a breaking change).

Iโ€™m gonna check now if thereโ€™s any short-term workaround to fix this issue in the meantime

Read more comments on GitHub >

github_iconTop Results From Across the Web

Asset metadata is not viewable on some folders after upgrade ...
The metadata schemas have been moved to a different location. Resolution. In AEM6.2, metadata forms have been moved from the /apps/dam/contentย ...
Read more >
Dynamic Media best practices guide
If you want to be still more proactive, you can use. API methods to check whether other assets or images exist using the...
Read more >
Online Manual - ~sedna GmbH
These pages give instructions on how to use the applications of the ~sedna software suite. The suite consists of the following applications:.
Read more >
NetX I/O 4 User Guide - Customer Support
The NetX I/O app provides a robust file transfer and synchronization tool that removes file management barriers and enables teams to work...
Read more >
assets folder(images,stylesheets,javascripts files) is not ...
after that css was not working properly check box is not visible, some images are not displaying in page. we try to rollback...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found