visionmedia / page.js

Micro client-side router inspired by the Express router
http://visionmedia.github.com/page.js
7.68k stars 689 forks source link

Sometimes it triggers twice on the same url #169

Open totty90 opened 9 years ago

A commented 9 years ago

Can you add some details to your issue? Test case?

totty90 commented 9 years ago

No, is just the default use case

    page('/', function(){
        game();
    })
    page('/terrain', function(){
        terrain();
    })
    page('*', function(){
        debugger
    })
    page({})

Both the '/' and '/terrain' triggers the function twice, but only sometimes. It really called it twice, I've used console.log to test it. Very strange, normally happens after a F5 refresh in google chrome.

A commented 9 years ago

It's sounds weird. Can you reproduce it somewhere on jsfiddle or codepen? Try master branch from the rawgit.

totty90 commented 9 years ago

It happens like once in 40 times... Is hard to reproduce

A commented 9 years ago

It's ok. I can refreshing pages all day long :D But I don't know is it your environment or page.js bug. And if you can help me figure out, then we resolve that issue faster.

totty90 commented 9 years ago

Ok. My env is using require.js and many other deps like (+tinycolor)

    'facebook'          : '//connect.facebook.net/en_US/all'
    // 'facebook'       : '//connect.facebook.net/en_US/sdk/debug'
    'requirejs'         : '../bower_components/requirejs/require',
    'react'             : '../bower_components/react/react-with-addons',
    'underscore'        : '../bower_components/lodash/dist/lodash',
    'futures-requirejs' : '../bower_components/futures-requirejs/future',
    'jquery'            : '../bower_components/jquery/jquery',
    // 'phaser'         : '../bower_components/phaser/phaser',
    'phaser'            : '../thirdParty/phaser/Phaser',
    'snap'              : '../bower_components/Snap.svg/dist/snap.svg',
    'proton'            : '../thirdParty/Proton',
    'copyProperties'    : '../thirdParty/copyProperties',
    'flux'              : '../bower_components/flux/dist/Flux',
    'eventEmitter'      : '../bower_components/eventEmitter/EventEmitter',
    'pixi'              : '../bower_components/pixi/bin/pixi',
    'crossroads'        : '../bower_components/crossroads/dist/crossroads',
    'signals'           : '../bower_components/js-signals/dist/signals',
    'hasher'            : '../bower_components/hasher/dist/js/hasher',
    'async'             : '../bower_components/async/lib/async',
    'socket.io-client'  : '../bower_components/socket.io-client/dist/socket.io',
    'html2canvas'       : '../bower_components/html2canvas/build/html2canvas.min',
    'hammer'            : '../bower_components/hammerjs/hammer',
    'touch-emulator'    : '../bower_components/hammer-touchemulator/touch-emulator',
    'moment'            : '../bower_components/moment/moment',
    // 'famous'         : '../bower_components/famous',
    'tinygradient'      : '../bower_components/tinygradient/tinygradient',
    'page'              : '../bower_components/page/index',
    // 'faker'          : '../bower_components/faker/dist/faker',
    'faker'             : '../thirdParty/Faker',
    'perlin'            : '../thirdParty/Perlin',

I can't reproduce the whole environment easily...

totty90 commented 9 years ago

Happened again:

Might not be a production issue... Don't know.

totty90 commented 9 years ago

I can confirm and reproduce in last chrome:

A commented 9 years ago

Wow, thank you for details!

supermensa commented 9 years ago

Happened for me too - a fix that worked in my case, was re-ordering the routes.

From:

  page('/products/:cat/:id', productsoverview);
  page('/product/:id', singleproduct);

To:

  page('/product/:id', singleproduct);
  page('/products/:cat/:id', productsoverview);