Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(sandstorm package): Synchronize URL to Sandstorm address bar #12

Open
paulproteus opened this issue Aug 9, 2015 · 8 comments
Open

Comments

@paulproteus
Copy link
Contributor

Steps to reproduce:

  • Be inside a Brainstorm in Sandstorm
  • Create a new Brainstorm
  • Create a new Brainstorm card, for example

pre-weird

  • Note that the app iframe has moved to a URL like /note/...
  • Reload the page (because why not)

Expected behavior:

  • See the same thing as you saw before the reload.

Actual behavior:

  • Find yourself wondering where your card went. Screenshot:

post-weird

Fix:

Add something like this to the HEAD element, to synchronize the app's current URL with Sandstorm:

https://gist.github.com/paulproteus/99373ffce3c277bf6ec2

Also note - in the future, I hope Sandstorm can make this issue go away by e.g. automatically running JS like this to synchronize the location. But since it's needed right now, I thought I should alert you to it.

@Azeirah
Copy link
Owner

Azeirah commented Aug 9, 2015

@paulproteus I tried adding that script to the head of my page, however it doesn't look like it's helping. I visit one of my fullscreen notes, refresh, and I'm back at the brainstorm homepage.

@paulproteus
Copy link
Contributor Author

Hmm, interesting. For what it's worth, I did write that with page-reload-based web apps in mind.

For Meteor, presumably the thing to do is to add it to some part of Iron Router. I'm not sure at the moment what the answer would be. @kentonv or @jparyani likely have more experience with that.

@paulproteus
Copy link
Contributor Author

Thinking out loud: maybe what you need here is a function that reactively looks at window.location (or a Meteor reactive version of window.location) and then runs the code on my gist.

@paulproteus
Copy link
Contributor Author

https://github.com/tmeasday/meteor-router/wiki/Split-API provides something like that, but note it's not for Iron Router.

It looks like maybe IronRouter.path is a reactive variable that does what we want.

@Azeirah
Copy link
Owner

Azeirah commented Aug 26, 2015

IronRouter.path seems to change reactively to what we want, except that it lags behind one route!

If I'm on home, and then click manage boards. The url is then "bla.sandstorm.io/bla/home", even though it should be ".../manageBoards" instead!

Tracker.autorun(function () {
        var path = Router.current();
        if (path) {
            window.parent.postMessage({'setPath': location.pathname + location.hash}, '*');
        }
    });

Same goes for the Router.after(function(){...}) callback, it lags behind one url!

It seems to work fine when using Meteor.defer(...)

Tracker.autorun(function () {
    Router.current();
    Meteor.defer(function () {
        window.parent.postMessage({'setPath': location.pathname + location.hash}, '*');
    });
});

Problem is, I don't know why... Regardless, the above script works perfectly, and will be included in the next Brainstorm release. My meteor-fu is really rusty, as I haven't really used it for over a year.. Perhaps you can shed some light on why the above code works? @paulproteus

Azeirah added a commit that referenced this issue Aug 26, 2015
@paulproteus
Copy link
Contributor Author

I think the reason is that location is set to the previous URL -- Router hasn't actually updated the browser yet, and the browser is in the middle of navigating.

Perhaps you can make this work by doing:

        if (path) {
            window.parent.postMessage({'setPath': path}, '*');
        }

but does path contain the full path (/a/b/c) as well as the #... (hash) component? That I don't know.

@paulproteus
Copy link
Contributor Author

Thanks so much for looking into this, @Azeirah !

@Azeirah
Copy link
Owner

Azeirah commented Aug 26, 2015

@paulproteus Nope, path doesn't contain the full path. There's Router.current().originalUrl and Router.current().url. Both look like "/board/whateverboard"..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants