{"action":"created","issue":{"url":"https://api.github.com/repos/Shopify/turbograft/issues/74","labels_url":"https://api.github.com/repos/Shopify/turbograft/issues/74/labels{/name}","comments_url":"https://api.github.com/repos/Shopify/turbograft/issues/74/comments","events_url":"https://api.github.com/repos/Shopify/turbograft/issues/74/events","html_url":"https://github.com/Shopify/turbograft/pull/74","id":58237872,"number":74,"title":"Optionally prevent PushState on Page.refresh without XHR","user":{"login":"maartenvg","id":3832753,"avatar_url":"https://avatars.githubusercontent.com/u/3832753?v=3","gravatar_id":"","url":"https://api.github.com/users/maartenvg","html_url":"https://github.com/maartenvg","followers_url":"https://api.github.com/users/maartenvg/followers","following_url":"https://api.github.com/users/maartenvg/following{/other_user}","gists_url":"https://api.github.com/users/maartenvg/gists{/gist_id}","starred_url":"https://api.github.com/users/maartenvg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maartenvg/subscriptions","organizations_url":"https://api.github.com/users/maartenvg/orgs","repos_url":"https://api.github.com/users/maartenvg/repos","events_url":"https://api.github.com/users/maartenvg/events{/privacy}","received_events_url":"https://api.github.com/users/maartenvg/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":12,"created_at":"2015-02-19T17:10:10Z","updated_at":"2015-03-19T10:51:05Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/Shopify/turbograft/pulls/74","html_url":"https://github.com/Shopify/turbograft/pull/74","diff_url":"https://github.com/Shopify/turbograft/pull/74.diff","patch_url":"https://github.com/Shopify/turbograft/pull/74.patch"},"body":"### Introduction\r\n\r\nCurrently we have 2 ways of doing a Page.refresh (also see #73). One where you have an XHR response you want to use to partially replace things in the page. And another where you give in a URI which you want to visit / (partially) refresh the current page, with or without some queryParams. \r\n\r\nSo \r\n\r\n```coffeescript\r\nPage.refresh\r\n  response: xhr\r\n  onlyKeys: [...]\r\n```\r\n\r\nvs\r\n\r\n```coffeescript\r\nPage.refresh\r\n  url: ... # optional, defaults to current page\r\n  queryParams: {...} # optional\r\n  onlyKeys: [...] # optional, defaults to full page refresh\r\n```\r\n\r\nIn the first case we don't do a `Turbolinks.pushState` when the refresh is done, which makes sense because you're not leaving the page. In the bottom case we do update the window state, but only if it is a new URL. 9 out of 10 times that's fine, because either you're visiting a completely new URI, or you're refreshing the current page which doesn't trigger the pushState because the URIs are identical.\r\n\r\n### Problem\r\n\r\nThere is a third case when you are trying to refresh the current page, but with new queryParams. This _does_ get recognized as a new URI, and will do a pushState. For example when you are on https://example.com/admin/article/1 and hit a button that does:\r\n\r\n```coffeescript\r\nPage.refresh\r\n  queryParams: {'myAwesomeParam': true}\r\n  onlyKeys: ['a_refresh_block']\r\n```\r\nIn this case your browser will update the address field to https://example.com/admin/article/1?myAwesomeParam=true.\r\n\r\nI'm arguing that there are situations where you want to refresh the page with a query param without actually touching the window state. For example to toggle a hide/show of something that requires new data from the server. In this PR I introduced a new option on `Page.refresh` that propagates down that prevents the page refresh optionally.  But to be honest I don't think it is common that you want to stay on the same URL, but with different query params, and have that reflected in the browser. In that case we could probably get away with just updating [turbolinks#reflectNewUrl](https://github.com/Shopify/turbograft/blob/78829dd7475ff25e15fdcecee81d466fa0fbcec1/lib/assets/javascripts/turbograft/turbolinks.coffee#L251) to ignore query params and only compare the root URIs.\r\n\r\nWhat do you guys think? @qq99 @nsimmons @celsodantas @richardmonette @DrewMartin Which way should we go?\r\n\r\n-----\r\n\r\n(A work around is doing the call with $.ajax, and using the resulting XHR in \r\n\r\n```coffeescript\r\nPage.refresh\r\n  response: xhr\r\n  onlyKeys: [...]\r\n```\r\nbut I feel turbograft should be able to deal with this)"},"comment":{"url":"https://api.github.com/repos/Shopify/turbograft/issues/comments/83502568","html_url":"https://github.com/Shopify/turbograft/pull/74#issuecomment-83502568","issue_url":"https://api.github.com/repos/Shopify/turbograft/issues/74","id":83502568,"user":{"login":"nsimmons","id":3313263,"avatar_url":"https://avatars.githubusercontent.com/u/3313263?v=3","gravatar_id":"","url":"https://api.github.com/users/nsimmons","html_url":"https://github.com/nsimmons","followers_url":"https://api.github.com/users/nsimmons/followers","following_url":"https://api.github.com/users/nsimmons/following{/other_user}","gists_url":"https://api.github.com/users/nsimmons/gists{/gist_id}","starred_url":"https://api.github.com/users/nsimmons/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nsimmons/subscriptions","organizations_url":"https://api.github.com/users/nsimmons/orgs","repos_url":"https://api.github.com/users/nsimmons/repos","events_url":"https://api.github.com/users/nsimmons/events{/privacy}","received_events_url":"https://api.github.com/users/nsimmons/received_events","type":"User","site_admin":false},"created_at":"2015-03-19T10:51:05Z","updated_at":"2015-03-19T10:51:05Z","body":"LGTM"}}