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

snapshot not load after refresh [$5] #3388

Closed
withinthefog opened this issue Apr 20, 2015 · 18 comments
Closed

snapshot not load after refresh [$5] #3388

withinthefog opened this issue Apr 20, 2015 · 18 comments
Assignees
Labels

Comments

@withinthefog
Copy link

Refresh page in nwjs 0.12.1 will Cause the snapshot to fail.

Here is the code to reproduce the Scenario:

package.json:

{
  "name": "nw-refresh",
  "main": "index.html"
}

index.html:

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>

<script src="app.js"></script>

</body>
</html>

app.js:

require('nw.gui').Window.get().evalNWBin(null, 'snapshot.bin');
var lib = require('./lib');

try {
    console.log('calling snapshot function from web...');
    echoInSnapshot();
} catch (e) {
    console.error('error calling snapshot function:', e.stack)
}

lib.callSnapshot();

lib.js:

exports.callSnapshot = function () {
    try {
        console.log('calling snapshot function from node...');
        echoInSnapshot();
    } catch (e) {
        console.error('call snapshot from node error:', e.stack);
    }
};

snapshot.js:

function echoInSnapshot() {
    console.log('in snapshot function')
}

Compile the snapshot.js using the command:

nwjc snapshot.js snapshot.bin

Start the nw.app, the log from app.js is collect, but if I hit the refresh(or refreshDev) button, there will be a RefrenceError says echoInSnapshot is not defined.

Also, calling snapshot functions from node context(like the code in lib.js above) will cause a RefrenceError echoInSnapshot is not defined. But in previous version(0.11.x), the functions in snapshot can be called Directly from a node context.

Did you help close this issue? Go claim the $5 bounty on Bountysource.

@liyingzh
Copy link

The refresh probelem is not reproducble on nwjs-v0.12.1-linux-x64.

nwjc uses code cache to write binary.bin, As v8 preserve code compiled in one context to use it in another context, the code has to be context-independent.
While nwsnapshot uses custom start-up snapshot which is not much different than V8's native scripts executed to initialize Javascript globals, so the functions in snapshot can be called everywhere.

@mscreenie
Copy link
Contributor

+1 reproducible on windows 8.1, nwjs 12.1 32bit with latest SSL fix @rogerwang did.

To reproduce: After launching your app reload - It will not call / load snapshot again. A big problem if you have code which initializes your app on page load.

This basic app will not work as expected. It will not run a second time when refreshed.

Using

var nw=require("nw.gui");
nw.Window.get().evalNWBin(null,"i/main.bin");

main.bin before compiled

console.log("Hello");

@mscreenie
Copy link
Contributor

I've reproduced this on Windows 7.

@withinthefog
Copy link
Author

@mscreenie @liyingzh thanks for reply.

This issue also happened on OS X.

@mscreenie
Copy link
Contributor

Noticed that the file is not loaded inside dev tools network tab, don't think it would show up in dev tools perhaps its loaded by io.js

perhaps @rogerwang has fixed this in nwjs 13 , ill check, but would be good to get a fix for 12.1 as its the preferred version of release right now.

@rogerwang
Copy link
Member

will fix this in next 0.12 version.

@rogerwang rogerwang self-assigned this May 11, 2015
@rogerwang rogerwang changed the title snapshot not load after refresh snapshot not load after refresh [$5] May 13, 2015
@mscreenie
Copy link
Contributor

Thanks @rogerwang ! A bit off topic - glad to see your decision on refracting code into sdk and distribution builds for nw13. Good decision.

Any idea on an eta for 12.2? Cheers. Would appreciate a release.

@rogerwang
Copy link
Member

It's expected to be released in this week.

@withinthefog
Copy link
Author

Thanks @rogerwang

@mscreenie
Copy link
Contributor

Excellent @rogerwang . Thanks for the update.

@rogerwang
Copy link
Member

I found that when you keep devtools closed the code reloads well. Change snapshot.js to something like: document.write(Date.now()) to workaround the windows console issue.

The reason is that v8 won't load the serialized code blob when debugger is attached: https://github.com/nwjs/v8/blob/nw12/src/compiler.cc#L1291

@mscreenie
Copy link
Contributor

I'll test this, but if I remember correctly it would not be called, ill see if having devtools closed makes a difference.

@mscreenie
Copy link
Contributor

When dev tools is closed snapshot is loaded runs ok, Makes debugging a little harder but then again I only compiled a snapshot when distributing the package.

Thanks roger, do you think its worth waiting around for 12.2 ? I'm going to push an update from 12 to latest soon.

@Egnus
Copy link

Egnus commented Jul 9, 2015

this is still happening. i Thought it was a problem of loading pages via Javascript but is definitely this the problem.
Avoid the opening of devtools should not be the final solution but a temporary workaround. Please consider a fix for the next version.
Tested today with nwjs v.12.2. I will test it without devtools soon.

@Egnus
Copy link

Egnus commented Jul 10, 2015

Tested, that was exactly the problem. without devtools bin code runs perfectly.
This has to be fixed anyway for the next version.

@mscreenie
Copy link
Contributor

Demanding that the issue should be fixed for the next version isn't going to make it fix faster and it's not the right way to request bug-fixes.

Considering roger is the sole maintainer of this project and likely has other commitments. I would use a softer approach and maybe attach a bounty to this bug.

@fritx
Copy link

fritx commented Jan 10, 2016

Any progress on this?
Luckily this works with devtools closed ;)

@rogerwang
Copy link
Member

The 'snapshot', which is the compiled binary code of JS, is now supported by a more flexible method: http://docs.nwjs.io/en/latest/References/Window/#winevalnwbinframe-path

It allows you load the compiled binary after reload.

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

No branches or pull requests

6 participants