Barba: Problem with back / forward buttons

Created on 20 Nov 2019  ·  3Comments  ·  Source: barbajs/barba

I have issues with back & forward buttons in the browser.

To recreate I have created very simple example. Two html files: test1 & test2, each with a simple link to the other file. Both with barba wrappers / containers.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body data-barba="wrapper">
    <div data-barba="container">
        test 1
        <br>
        <a href="test2.php">next page</a>
    </div>
</body>
    <script src="test.js"></script>
</html>

Then a simple transitions initialization:

barba.init({
    transitions: [
        {
            name: 'generic',
            priority: 2,
            enter() {
                console.log('generic enter');
            },
        }, {
            name: 'back',
            priority: 1,
            custom: ({ trigger }) => {return trigger === 'back'},
            enter() {
                console.log('back enter')
            },
        }, {
            name: 'forward',
            priority: 1,
            custom: ({ trigger }) => {return trigger === 'forward'},
            enter() {
                console.log('forward enter')
            },
        },
    ]
    });

Now the test scenario is:

  1. go through a few links... This results in a bunch of "generic enter" logs. So far so good.
  2. now reload.
  3. go back (browser nav button). I see forward log.
  4. go forward (browser nav button). I see back log.
    I consider both a bug.
  5. go back twice (still the nav button). I see forward log followed with a back log. (further backs result in a back log which is fine).
  6. go further twice... I see forward log (ok) followed with a back log (bug).

I can attach a simple repo should you need it to recreate. Using barba 2.8.0.

@barbcore bug v2

Most helpful comment

Hi @pburdylo,

Thanks for pointing this out.
We need to check barba.history on popstate events.
I will work on it tomorrow and release a quick fix.
Alongside, we will probably consider some refactoring around this history management…

All 3 comments

Hi @pburdylo,

Thanks for the use case. Note that your script src is outside the body tag.
Will take the time to check all scenarios as soon as possible.

:wink:

Hi @pburdylo,

Thanks for pointing this out.
We need to check barba.history on popstate events.
I will work on it tomorrow and release a quick fix.
Alongside, we will probably consider some refactoring around this history management…

@pburdylo,

It should be fixed in 2.9.3.
And it would be very appreciated if you could check and validate… 😊

Was this page helpful?
0 / 5 - 0 ratings

Related issues

shanewmurphy picture shanewmurphy  ·  3Comments

shanewmurphy picture shanewmurphy  ·  3Comments

luglio7 picture luglio7  ·  4Comments

pierredarrieutort picture pierredarrieutort  ·  3Comments

hugobqd picture hugobqd  ·  3Comments