Skip to content

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

Description

@tychota

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 ea980fd#diff-71293ea379a7cf006cd4648701a7c568 (#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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions