Skip to content
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

Fix iOS unchanged local assets refetched from packager in development #9795

Conversation

jeanregisser
Copy link
Contributor

@jeanregisser jeanregisser commented Sep 7, 2016

Hi,

This PR fixes the problem described by @chrisnojima in #9581 (comment)

Test plan

In development mode,

  • Run an app with an image: <Image source={ require('./logo.png') }/>
  • Notice that you see the following in packager console:
6:46:42 PM] <START> processing asset request logo.png
[6:46:42 PM] <END>   processing asset request logo.png (1ms)
  • Reload the app, or navigate to another page of the app with the same image
  • Notice that you see again:
6:47:23 PM] <START> processing asset request logo.png
[6:47:23 PM] <END>   processing asset request logo.png (1ms)

Now wih the fix applied,
notice that you only see logo.png fetched once, even if you reload or show the same image in a different part of the app.

Let me know what you think.

@ghost
Copy link

ghost commented Sep 7, 2016

By analyzing the blame information on this pull request, we identified @davidaurelio and @frantic to be potential reviewers.

@ghost ghost added GH Review: review-needed CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. labels Sep 7, 2016
@jeanregisser
Copy link
Contributor Author

Also see my comment #9581 (comment) which explains what caused the issue.

@mkonicek
Copy link
Contributor

mkonicek commented Sep 8, 2016

@jeanregisser I agree #9581 is a pretty important issue - in production images should be cached and not always refetched.

Why not always refetch them from the packager during development though?

With the change in this PR, what if I update the logo.png in the filesystem and Reload JS? The app should render the new logo immediately. Will it?

@ghost ghost added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 8, 2016
@jeanregisser
Copy link
Contributor Author

I think it's unexpected to always refetch the same local assets in development mode.

For instance, if you have a screen showing 10 local images, the first time it's displayed, they are going to be fetched from the packager and this is normal and expected.
Now if you have another screen using the same local images, it's unexpected that you don't see them immediately as they are refetched again when you navigate to it.

Up until RN < 0.31.0 local images were just fetched once (unless you changed them).

The PR restores this behavior on iOS. And if you change logo.png and reload, you'll see the new logo as expected.
On Android it doesn't change anything. It was already behaving that way.

@jeanregisser
Copy link
Contributor Author

@mkonicek what do you think of my answer?

@ghost ghost added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 16, 2016
@davidaurelio
Copy link
Contributor

Thanks for repairing this!

@davidaurelio
Copy link
Contributor

@facebook-github-bot shipit

@ghost ghost added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. GH Review: accepted Import Started This pull request has been imported. This does not imply the PR has been approved. and removed GH Review: review-needed labels Sep 16, 2016
@facebook-github-bot
Copy link
Contributor

Thanks for importing. If you are an FB employee go to Phabricator to review internal test results.

@ghost ghost added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 16, 2016
@davidaurelio
Copy link
Contributor

@jeanregisser there are a couple of tests failing. Could you fix or adapt them, please?

@jeanregisser
Copy link
Contributor Author

Yes. I'll have a look.

@ghost ghost added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 16, 2016
@ghost
Copy link

ghost commented Sep 17, 2016

I tried to merge this pull request into the Facebook internal repo but some checks failed. To unblock yourself please check the following: Does this pull request pass all open source tests on GitHub? If not please fix those. Does the code still apply cleanly on top of GitHub master? If not can please rebase. In all other cases this means some internal test failed, for example a part of a fb app won't work with this pull request. I've added the Import Failed label to this pull request so it is easy for someone at fb to find the pull request and check what failed. If you don't see anyone comment in a few days feel free to comment mentioning one of the core contributors to the project so they get a notification.

@ghost ghost added Import Failed CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. and removed Import Started This pull request has been imported. This does not imply the PR has been approved. labels Sep 17, 2016
data => res.end(this._rangeRequestMiddleware(req, res, data, assetPath)),
data => {
// Tell clients to cache this for 1 year.
// This is safe as the asset url contains a hash of the mtime of the asset.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this say hash of the asset files instead of mtime now?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated thanks.

@jeanregisser jeanregisser force-pushed the fix-local-assets-refetched-in-development branch from c0ba6c8 to f272ff2 Compare September 19, 2016 09:16
@ghost
Copy link

ghost commented Sep 19, 2016

@jeanregisser updated the pull request - view changes - changes since last import

@ghost ghost added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 19, 2016
@ghost ghost closed this in 1a3e6eb Sep 19, 2016
cpojer pushed a commit to facebook/metro that referenced this pull request Jan 26, 2017
Summary:
Hi,

This PR fixes the problem described by chrisnojima in facebook/react-native#9581 (comment)

**Test plan**

In development mode,
- Run an app with an image: `<Image source={ require('./logo.png') }/>`
- Notice that you see the following in packager console:
```txt
6:46:42 PM] <START> processing asset request logo.png
[6:46:42 PM] <END>   processing asset request logo.png (1ms)
```
- Reload the app, or navigate to another page of the app with the same image
- Notice that you see again:
```txt
6:47:23 PM] <START> processing asset request logo.png
[6:47:23 PM] <END>   processing asset request logo.png (1ms)
```

Now wih the fix applied,
notice that you only see `logo.png` fetched once, even if you reload or show the same image in a different part of the app.

Let me know what you think.
Closes facebook/react-native#9795

Differential Revision: D3876945

Pulled By: davidaurelio

fbshipit-source-id: f41f4719e87644692a690123fd6e54eead9cc87d
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants