title: Conditional addition to back stack
body: <p>I have the following working code : </p>
  
  <pre><code>if (bottomViewState.addToBackStack) {
          fragmentManager!!.beginTransaction()
              .replace(R.id.bottomNavHostFragment, bottomViewState.fragment, bottomViewState.tag.toString())
              .addToBackStack(null)
              .commit()
      } else {
          fragmentManager!!.beginTransaction()
              .replace(R.id.bottomNavHostFragment, bottomViewState.fragment, bottomViewState.tag.toString())
              .commit()
      }
  }
  </code></pre>
  
  <p>I use this for a bottom navigation, this way I can navigate back from a detail fragment to it's parent, but I don't add transaction between item of the bottom bar in the back stack. My issue appears when I try to refactor this code to the following :</p>
  
  <pre><code>val transaction = fragmentManager!!.beginTransaction()
  transaction.replace(R.id.bottomNavHostFragment, bottomViewState.fragment, bottomViewState.tag.toString())
  
  if(bottomViewState.addToBackStack) {
      transaction.addToBackStack(null)
  }
  
  transaction.commit()
  </code></pre>
  
  <p>The problem with this code is that my fragment are never displayed, like if the transaction was not committed. What am I doing wrong here?</p>