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

.wasm files are too aggressively cached by the server #1376

Closed
1 of 2 tasks
fitzgen opened this issue Apr 12, 2018 · 10 comments
Closed
1 of 2 tasks

.wasm files are too aggressively cached by the server #1376

fitzgen opened this issue Apr 12, 2018 · 10 comments

Comments

@fitzgen
Copy link

fitzgen commented Apr 12, 2018

  • Operating System: Linux big-beefy 4.13.0-38-generic Multiple bundles with different publicPaths #43-Ubuntu SMP Wed Mar 14 15:20:44 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
  • Node Version: v9.3.0
  • NPM Version: 5.8.0
  • webpack Version: 4.4.1
  • webpack-dev-server Version: 3.1.1
  • This is a bug
  • This is a modification request

Code

Test case: https://github.com/rustwasm/wasm_game_of_life/tree/d1d20e6b8ffe9f63e8a058055d5696ede0a41927

Expected Behavior

Modifying the .wasm triggers a refresh of the page with the new .wasm modifications reflected, just like modifying JS files does.

Actual Behavior

The .wasm seems to be too aggressively cached by webpack-dev-server, and changes to it are not reflected on the page unless the server is restarted.

(Note: I verified that disabling the network cache in the browser results in fresh 200 requests for the .wasm but that the response payload is not the modified .wasm on disk, ergo this bug is not the browser's network cache acting up.)

For Bugs; How can we reproduce the behavior?

  • Install the rust toolchain so you can modify and recompile the .wasm, as described in https://rust-lang-nursery.github.io/rust-wasm/game-of-life/setup.html

  • cd wasm_game_of_life

  • npm install

  • npm run serve in a new terminal, so it will keep running

  • verify that the game of life is working at http://localhost:8080

  • In src/lib.rs, find the pub fn new() -> Universe method. Replace its body with panic!():

    pub fn new() -> Universe {
      panic!()
    }
  • npm run build-debug to rebuild the .wasm with the panic changes

  • refresh http://localhost:8080 -- it should not have a working game of life anymore, and there should be an error in the console from the panic. If it is still working, then that means the new .wasm was not loaded.

@alexcrichton
Copy link

For a slightly more self-contained reprodution:

  • Clone https://github.com/alexcrichton/webpack-dev-server-issue-1376
  • cd into checkout directory
  • npm install
  • cp add1.wasm add.wasm
  • npm run serve
  • Open a web browser to http://localhost:8080, you should see a dialog with "2" (1 + 1 = 2)
  • In a different terminal (while npm run serve is still running), execute cp add2.wasm add.wasm
    • This simulates the wasm being updated from a Rust compilation or something like that
  • Notice how webpack-dev-server rebuilds... something?
  • Refresh the web page. It's expected to see 3 (1 + 2 = 3), but you currently see 2
  • Kill and restart npm run serve
  • Refresh the web page, you'll now see 3

@jasondavies
Copy link

Just ran into this too. If someone can point me to the relevant module(s) for webpack I can take a look.

@glenjamin
Copy link
Contributor

I think this is an issue in webpack itself rather than webpack-dev-server.

Steps to reproduce without using dev server:

  1. Modify the package.json and add this to scripts: "build": "webpack"
  2. cp add1.wasm add.wasm
  3. npm run build - shows 8272f8059cff031ea68e.module.wasm in bundle
  4. git grep --untracked '{"./add.wasm":' dist/ - shows 8272f8059cff031ea68e in bundle
  5. cp add2.wasm add.wasm
  6. npm run build - shows 767437f29c6ec784dbb9.module.wasm in bundle
  7. git grep --untracked '{"./add.wasm":' dist/ - shows 767437f29c6ec784dbb9 in bundle
  8. npm run build -- --watch and leave it running
  9. cp add1.wasm add.wasm - shows 8272f8059cff031ea68e.module.wasm in bundle
  10. git grep --untracked '{"./add.wasm":' dist/ - shows 767437f29c6ec784dbb9 in bundle

@sendilkumarn
Copy link
Member

@glenjamin Nice catch.

cc: @xtuc & @sokra do you guys have any idea about this?

@xtuc
Copy link
Member

xtuc commented Apr 27, 2018

I don't know how works the caching strategy in Webpack. Maybe it can not compare binary files?

sokra added a commit to webpack/webpack that referenced this issue May 2, 2018
sokra added a commit to webpack/webpack that referenced this issue May 2, 2018
@sokra
Copy link
Member

sokra commented May 2, 2018

This is fixed in the "next" branch in webpack/webpack. We are working on upgrading the WASM pipeline and will merge this to master in a few days.

@alexcrichton
Copy link

Awesome, thanks so much @sokra!

@sendilkumarn
Copy link
Member

@xtuc whether the other issue fixes (which we were discussing) landed in next already ?

@alexcrichton
Copy link

I can confirm this is now fixed on Webpack 4.8

Nice!

@alexander-akait
Copy link
Member

Looks like we can close issue! Please upgrade to webpack4.8. If problem still exists after upgrade feel free reopen 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants