Clicking on BackButton on Chrome has incorrect behaviour once an iframe needs to be reloaded





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I have to rerender an iframe once the user clicks on the backbutton, however if clicking the backbutton will result in reloading the iframe the first click is ignored, so you essentially need to click the backbutton twice in order for it to work.



Here is the code:



import React, { Component } from 'react';
import { createBrowserHistory } from 'history';
import qs from 'qs';

const history = createBrowserHistory();
const QUERY_PARAM_DELIMETER = ',';

class App extends Component {
state = {
bar: ''
}

updateQuery = () => {
setQueryParam('bar', 'foo');
this.setState({
bar: 'foo'
})
}

render() {
return (
<div>
<iframe title="chat" src={"https://www.twitch.tv/embed/beyondthesummit/chat?bar=" + this.state.bar } frameBorder="0" scrolling="no" height="500" width="350"></iframe>
<button onClick={this.updateQuery}>Add random query param</button>
</div>
);
}
}

export default App;

function setQueryParam(key, val) {
const queryObj = parseQueryObj();

if (Array.isArray(val)) {
/* eslint-disable no-param-reassign */
val = val.join(QUERY_PARAM_DELIMETER);
/* eslint-enable no-param-reassign */
}

queryObj[key] = val;

// Delete prop in case the value is empty
if (queryObj[key] === undefined || queryObj[key] === '' || (Array.isArray(queryObj[key]) && !queryObj[key].length)) {
delete queryObj[key];
}

return pushQueryObj(queryObj);
};

function pushQueryObj(queryObj) {
const search = qs.stringify(queryObj, { encode: false });

// We dont want to push to history if there will be no change in the url
if (history.location.search.split('?').pop() === search) {
return;
}

return history.push({ search });
}

function parseQueryObj() {
return qs.parse(history.location.search, { ignoreQueryPrefix: true });
}


Its very simple example aiming to reproduce the issue. Once the component is mounted, you click on the Add random query param button, which will change the url and trigger iframe reload. If you try to go back, expected behaviour would be to be to the first page, but this doesnt happen. Instead, you have to click twice in order to actually go back.










share|improve this question





























    0















    I have to rerender an iframe once the user clicks on the backbutton, however if clicking the backbutton will result in reloading the iframe the first click is ignored, so you essentially need to click the backbutton twice in order for it to work.



    Here is the code:



    import React, { Component } from 'react';
    import { createBrowserHistory } from 'history';
    import qs from 'qs';

    const history = createBrowserHistory();
    const QUERY_PARAM_DELIMETER = ',';

    class App extends Component {
    state = {
    bar: ''
    }

    updateQuery = () => {
    setQueryParam('bar', 'foo');
    this.setState({
    bar: 'foo'
    })
    }

    render() {
    return (
    <div>
    <iframe title="chat" src={"https://www.twitch.tv/embed/beyondthesummit/chat?bar=" + this.state.bar } frameBorder="0" scrolling="no" height="500" width="350"></iframe>
    <button onClick={this.updateQuery}>Add random query param</button>
    </div>
    );
    }
    }

    export default App;

    function setQueryParam(key, val) {
    const queryObj = parseQueryObj();

    if (Array.isArray(val)) {
    /* eslint-disable no-param-reassign */
    val = val.join(QUERY_PARAM_DELIMETER);
    /* eslint-enable no-param-reassign */
    }

    queryObj[key] = val;

    // Delete prop in case the value is empty
    if (queryObj[key] === undefined || queryObj[key] === '' || (Array.isArray(queryObj[key]) && !queryObj[key].length)) {
    delete queryObj[key];
    }

    return pushQueryObj(queryObj);
    };

    function pushQueryObj(queryObj) {
    const search = qs.stringify(queryObj, { encode: false });

    // We dont want to push to history if there will be no change in the url
    if (history.location.search.split('?').pop() === search) {
    return;
    }

    return history.push({ search });
    }

    function parseQueryObj() {
    return qs.parse(history.location.search, { ignoreQueryPrefix: true });
    }


    Its very simple example aiming to reproduce the issue. Once the component is mounted, you click on the Add random query param button, which will change the url and trigger iframe reload. If you try to go back, expected behaviour would be to be to the first page, but this doesnt happen. Instead, you have to click twice in order to actually go back.










    share|improve this question

























      0












      0








      0








      I have to rerender an iframe once the user clicks on the backbutton, however if clicking the backbutton will result in reloading the iframe the first click is ignored, so you essentially need to click the backbutton twice in order for it to work.



      Here is the code:



      import React, { Component } from 'react';
      import { createBrowserHistory } from 'history';
      import qs from 'qs';

      const history = createBrowserHistory();
      const QUERY_PARAM_DELIMETER = ',';

      class App extends Component {
      state = {
      bar: ''
      }

      updateQuery = () => {
      setQueryParam('bar', 'foo');
      this.setState({
      bar: 'foo'
      })
      }

      render() {
      return (
      <div>
      <iframe title="chat" src={"https://www.twitch.tv/embed/beyondthesummit/chat?bar=" + this.state.bar } frameBorder="0" scrolling="no" height="500" width="350"></iframe>
      <button onClick={this.updateQuery}>Add random query param</button>
      </div>
      );
      }
      }

      export default App;

      function setQueryParam(key, val) {
      const queryObj = parseQueryObj();

      if (Array.isArray(val)) {
      /* eslint-disable no-param-reassign */
      val = val.join(QUERY_PARAM_DELIMETER);
      /* eslint-enable no-param-reassign */
      }

      queryObj[key] = val;

      // Delete prop in case the value is empty
      if (queryObj[key] === undefined || queryObj[key] === '' || (Array.isArray(queryObj[key]) && !queryObj[key].length)) {
      delete queryObj[key];
      }

      return pushQueryObj(queryObj);
      };

      function pushQueryObj(queryObj) {
      const search = qs.stringify(queryObj, { encode: false });

      // We dont want to push to history if there will be no change in the url
      if (history.location.search.split('?').pop() === search) {
      return;
      }

      return history.push({ search });
      }

      function parseQueryObj() {
      return qs.parse(history.location.search, { ignoreQueryPrefix: true });
      }


      Its very simple example aiming to reproduce the issue. Once the component is mounted, you click on the Add random query param button, which will change the url and trigger iframe reload. If you try to go back, expected behaviour would be to be to the first page, but this doesnt happen. Instead, you have to click twice in order to actually go back.










      share|improve this question














      I have to rerender an iframe once the user clicks on the backbutton, however if clicking the backbutton will result in reloading the iframe the first click is ignored, so you essentially need to click the backbutton twice in order for it to work.



      Here is the code:



      import React, { Component } from 'react';
      import { createBrowserHistory } from 'history';
      import qs from 'qs';

      const history = createBrowserHistory();
      const QUERY_PARAM_DELIMETER = ',';

      class App extends Component {
      state = {
      bar: ''
      }

      updateQuery = () => {
      setQueryParam('bar', 'foo');
      this.setState({
      bar: 'foo'
      })
      }

      render() {
      return (
      <div>
      <iframe title="chat" src={"https://www.twitch.tv/embed/beyondthesummit/chat?bar=" + this.state.bar } frameBorder="0" scrolling="no" height="500" width="350"></iframe>
      <button onClick={this.updateQuery}>Add random query param</button>
      </div>
      );
      }
      }

      export default App;

      function setQueryParam(key, val) {
      const queryObj = parseQueryObj();

      if (Array.isArray(val)) {
      /* eslint-disable no-param-reassign */
      val = val.join(QUERY_PARAM_DELIMETER);
      /* eslint-enable no-param-reassign */
      }

      queryObj[key] = val;

      // Delete prop in case the value is empty
      if (queryObj[key] === undefined || queryObj[key] === '' || (Array.isArray(queryObj[key]) && !queryObj[key].length)) {
      delete queryObj[key];
      }

      return pushQueryObj(queryObj);
      };

      function pushQueryObj(queryObj) {
      const search = qs.stringify(queryObj, { encode: false });

      // We dont want to push to history if there will be no change in the url
      if (history.location.search.split('?').pop() === search) {
      return;
      }

      return history.push({ search });
      }

      function parseQueryObj() {
      return qs.parse(history.location.search, { ignoreQueryPrefix: true });
      }


      Its very simple example aiming to reproduce the issue. Once the component is mounted, you click on the Add random query param button, which will change the url and trigger iframe reload. If you try to go back, expected behaviour would be to be to the first page, but this doesnt happen. Instead, you have to click twice in order to actually go back.







      reactjs google-chrome react-router






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 4 at 16:56









      nikksannikksan

      1,069918




      1,069918
























          0






          active

          oldest

          votes












          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54043119%2fclicking-on-backbutton-on-chrome-has-incorrect-behaviour-once-an-iframe-needs-to%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54043119%2fclicking-on-backbutton-on-chrome-has-incorrect-behaviour-once-an-iframe-needs-to%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Angular Downloading a file using contenturl with Basic Authentication

          Olmecas

          Can't read property showImagePicker of undefined in react native iOS