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.

React packager does not reload required HTML file for WebView

See original GitHub issue

Description

I have simple HTML file asset and are using WebView to display it. Works fine for first time but when I reload simulator with cmd-r the HTML file is not reloaded when I change it.

        <WebView
          style={{width: 300}}
          source={require('./html/index.html')}
          javaScriptEnabled={true}
          />

logs from packager:

[11/4/2016, 10:56:31 AM] <END>   Initializing Packager (559ms)
[11/4/2016, 10:56:35 AM] <START> Requesting bundle: {"url":"/index.ios.bundle?platform=ios&dev=true&minify=false"}
[11/4/2016, 10:56:35 AM] <START> Transforming modules
transformed 644/644 (100%)
[11/4/2016, 10:56:35 AM] <END>   Transforming modules (353ms)
[11/4/2016, 10:56:35 AM] <END>   Requesting bundle: {"url":"/index.ios.bundle?platform=ios&dev=true&minify=false"} (466ms)
[11/4/2016, 10:56:36 AM] <START> Processing asset request: {"asset":"html/index.html"}
[11/4/2016, 10:56:36 AM] <END>   Processing asset request: {"asset":"html/index.html"} (4ms)
[11/4/2016, 10:56:46 AM] <START> Requesting bundle: {"url":"/index.ios.bundle?platform=ios&dev=true&minify=false"}
[11/4/2016, 10:56:46 AM] <END>   Requesting bundle: {"url":"/index.ios.bundle?platform=ios&dev=true&minify=false"} (28ms)
[11/4/2016, 10:57:09 AM] <START> Requesting bundle: {"url":"/index.ios.bundle?platform=ios&dev=true&minify=false"}
[11/4/2016, 10:57:09 AM] <START> Transforming modules
transformed 644/644 (100%)
[11/4/2016, 10:57:09 AM] <END>   Transforming modules (366ms)
[11/4/2016, 10:57:10 AM] <END>   Requesting bundle: {"url":"/index.ios.bundle?platform=ios&dev=true&minify=false"} (537ms)

as we can see html is served only once. HTML is reloaded (once) after manually restarting packager.

Additional Information

  • React Native version: “react-native”: “0.36.1”
  • Platform: iOS (android not tested)
  • Operating System: MacOS

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:4
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
grabcodecommented, Nov 14, 2016

@@dannycochran I’ve trouble check the issue you have, and it is not strictly due to the same reason. You’re problem comes down node_modules/react-native/packager/react-packager/src/Server/index.js:

res.setHeader('Cache-Control', 'max-age=31536000');

You may fix it yourself doing:

if (process.env.NODE_ENV === 'production') {
  res.setHeader('Cache-Control', 'max-age=31536000');
}

I’m going to propose another PR on 0.37.x: https://github.com/facebook/react-native/pull/10919

Cheers, Alex

1reaction
grabcodecommented, Nov 7, 2016

I reckon the issue might concern any assets as a matter of fact.

It seems to be due to the latest changes made on the AssetServer. It used to work before, and then I was using RN 0.34.0.

I’m currently working around the issue editing the file node_modules/react-native/packager/react-packager/src/AssetServer/index.js:

_onFileChange(type, assetRelativePath, root) {
    const assetPath = this._files.get(path.join(root, assetRelativePath));
    if (assetPath) {
      this._hashes.delete(assetPath);
    }
  }

Once I’ve pinpointed the solution, I’ll share it around, unless anyone comes first 😉.

Read more comments on GitHub >

github_iconTop Results From Across the Web

(React Native) Load local HTML file into WebView
6 Answers 6 · Add your .html file in your project. · Write such lines of code in the file where you want...
Read more >
No way to load a local HTML file in the webview on Android
Bug description: I have a file with name index.html. I'm trying to load the file into the webview. However, there seems to be...
Read more >
Load Local HTML File or URL in React Native using ...
How to open any URL, Local HTML File and or any HTML in Recat native App using WebView component provided by react-native-webview.
Read more >
React Native: How to Load SPA or Static HTML Site inside ...
React Native WebView allows you to load a publicly accessible resource with the uri property. It works just as a usual website inside...
Read more >
WebView
Loads static HTML or a URI (with optional headers) in the WebView. Note that static HTML will require setting originWhitelist to ["*"] ....
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