Repository: jupyterhub/jupyterhub

Issue:
Options form seems to kill page refresh
**How to reproduce the issue**

Use an options form in the spawner.

**What you expected to happen**

With no options form, when I start a server, I get a page with a blue refresh button until it actually starts the container (I am using JupyterHub plus a slightly-modified Kubespawner, with Lab inside the Kube container), and then I am redirected there.

This is the behavior I expect.

**What actually happens**

When I use an options form, it goes back to the "Start My Server" button and does not refresh.  Putting a refresh in the options form refreshes that form, but once you submit the form, you're back at "Start My Server" only minus any auto-refresh.  If you reload the page manually it works as expected to show "My Server" once it's started up, and then you can click it and go to your server.

**Share what version of JupyterHub you are using**

JupyterHub 0.8.0-dev0 (GitHub master branch, last pulled Thursday May 18).

Options form looks like


```python
# Add selection form
c.SQREKubeSpawner.options_form = """
<script>
     var time = new Date().getTime();
     $(document.body).bind("mousemove keypress", function(e) {
         time = new Date().getTime();
     });

     function refresh() {
         if(new Date().getTime() - time >= 60000)
             window.location.reload(true);
         else
             setTimeout(refresh, 10000);
     }

     setTimeout(refresh, 10000);
</script>
<label for="LSST Stack Selector">LSST Stack Selector</label></br>
<input type="radio" name="lsst_stack"
  value="lsstsqre/jld-lab-py2:latest"> Python 2
<input type="radio" name="lsst_stack"
  value="lsstsqre/jld-lab-py3:latest"> Python 3
"""
```

jupyter troubleshoot:

```
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
$PATH:
	/usr/bin
	/usr/local/sbin
	/usr/local/bin
	/usr/sbin
	/usr/bin
	/sbin
	/bin

sys.path:
	/usr/bin
	/usr/lib64/python34.zip
	/usr/lib64/python3.4
	/usr/lib64/python3.4/plat-linux
	/usr/lib64/python3.4/lib-dynload
	/usr/lib64/python3.4/site-packages
	/usr/lib/python3.4/site-packages

sys.executable:
	/usr/bin/python3.4

sys.version:
	3.4.5 (default, Nov  9 2016, 16:24:59)
	[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)]

platform.platform():
	Linux-4.4.35+-x86_64-with-centos-7.3.1611-Core

pip list:
	alembic (0.9.1)
	backports-abc (0.5)
	bleach (2.0.0)
	decorator (4.0.11)
	entrypoints (0.2.2)
	html5lib (0.999999999)
	ipykernel (4.6.1)
	ipython (6.0.0)
	ipython-genutils (0.2.0)
	jedi (0.10.2)
	Jinja2 (2.9.6)
	jsonschema (2.6.0)
	jupyter-client (5.0.1)
	jupyter-core (4.3.0)
	jupyterhub (0.8.0.dev0)
	jupyterlab (0.21.0)
	jupyterlab-launcher (0.2.8)
	Mako (1.0.6)
	MarkupSafe (1.0)
	mistune (0.7.4)
	nbconvert (5.1.1)
	nbformat (4.3.0)
	notebook (5.0.0)
	oauthenticator (0.5.1)
	pamela (0.3.0)
	pandocfilters (1.4.1)
	pexpect (4.2.1)
	pickleshare (0.7.4)
	pip (9.0.1)
	prompt-toolkit (1.0.14)
	ptyprocess (0.5.1)
	pycurl (7.43.0)
	Pygments (2.2.0)
	python-dateutil (2.6.0)
	python-editor (1.0.3)
	python-oauth2 (1.0.1)
	PyYAML (3.12)
	pyzmq (16.0.2)
	requests (2.14.2)
	setuptools (19.2)
	simplegeneric (0.8.1)
	six (1.10.0)
	SQLAlchemy (1.1.9)
	sqre-ghowlauth (0.0.9)
	sqrekubespawner (0.0.7)
	terminado (0.6)
	testpath (0.3)
	tornado (4.5.1)
	traitlets (4.3.2)
	typing (3.6.1)
	wcwidth (0.1.7)
	webencodings (0.5.1)

```



Discussion:
What is the javascript refresh expected to accomplish? It doesn't make sense to me to automatically refresh a form page.

Since you are seeing the 'slow startup' page without the options form, my first guess is that we aren't handling the slow spawn case correctly when options_form is enabled.

Resolving patch:
diff --git a/jupyterhub/handlers/pages.py b/jupyterhub/handlers/pages.py
--- a/jupyterhub/handlers/pages.py
+++ b/jupyterhub/handlers/pages.py
@@ -67,13 +67,9 @@ def get(self):
         if user.running:
             # trigger poll_and_notify event in case of a server that died
             yield user.spawner.poll_and_notify()
-            url = user.url
-        else:
-            url = url_concat(url_path_join(self.base_url, 'spawn'),
-                             {'next': self.request.uri})
         html = self.render_template('home.html',
             user=user,
-            url=url,
+            url=user.url,
         )
         self.finish(html)
 


Test patch: