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

Electron: root reload error #72

Open
ungoldman opened this issue Dec 16, 2016 · 8 comments
Open

Electron: root reload error #72

ungoldman opened this issue Dec 16, 2016 · 8 comments

Comments

@ungoldman
Copy link

One last fix needed for electron:

Electron pathname regex needs to be updated to account for file:/// being equivalent to /.

steps to reproduce
  • Navigate to a route (.e.g. /users) and then back to root (/).
    • pathname is set to /.
  • Reload page.
  • Error:
Not allowed to load local resource: file:///

Will try to send a PR today.

@ungoldman
Copy link
Author

ungoldman commented Dec 17, 2016

from @bcomnes in hypermodules/hyperamp#68:

bug

This was another sheet-router bug I was running into. Basically, refreshing the app should work everywhere, but after you navigate around, you lose the base url so subsequent refreshes fail. The gif shows 1 working refresh (initial state) and one failed refresh at the end. I need to open an issue upstream. Going to 🛏 goodnight 🌖

@ungoldman
Copy link
Author

Dumb fix is just adding .replace('file://', ''). Regexes tho 💀

@bcomnes
Copy link

bcomnes commented Dec 18, 2016

I tried that, but with the old regex. So close! 😭

@ungoldman
Copy link
Author

I think this may be just be a hard limitation of running choo in electron without a server. sheet-router is just not set up to deal with the file protocol. Absolute links will always break on reload because / will never map to /Users/.../cwd/index.html.

When you reload with electron, it tries to reload whatever the current document.location is. After navigating somewhere like /foo then back to /, choo/sheet-router's push state manipulation rewrites the location object to look something like:

ancestorOrigins: DOMStringList
assign: function ()
hash: ""
host: ""
hostname: ""
href: "file:///"
origin: "file://"
pathname: "/"
port: ""
protocol: "file:"
reload: function reload ()
replace: function ()
search: ""

So a reload will cause electron to try to load a file from file:///. Since there is no file to load there, and choo isn't there to reinterpret the path to something relative to the initial index.html, it will always fail.

I think for choo to work reliably in an electron environment, there either has to be a server, or sheet-router has to be rewritten to work specifically for an electron environment where routes don't correspond to server routes, and location.href needs to always point to the originating index.html.

Maybe only using hash routing in electron contexts is an interim solution?

@bcomnes
Copy link

bcomnes commented Dec 18, 2016

We could also fix https://github.com/hypermodules/choo-location-electron to work with the new sheet router / choo. Things works pretty well using that arrangement.

@ungoldman
Copy link
Author

ungoldman commented Jan 9, 2017

Note: couldn't get hash routing to work in electron either

@bcomnes
Copy link

bcomnes commented Apr 20, 2017

Switched to using nanorouter and hashes. Works great. Good to close.

@yoshuawuyts
Copy link
Owner

yoshuawuyts commented Apr 21, 2017 via email

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

3 participants