-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
updateQueryString
doesn't work with shinylive
#4153
Comments
Relatedly, observeEvent(session$clientData$url_hash, {
...
}) Again, I believe changing the typescript code to use |
Thanks for opening the issue and the suggestion. We've discussed this in posit-dev/r-shinylive#28 and have done some work in this direction in posit-dev/shinylive#79.
Unfortunately, I doubt it'd be this easy. For example, this change would be likely to break behavior where an app inside an Another complication is that it's very hard to judge the impact of this kind of change. In these cases we tend toward cautiously evaluating the change from first principles, which means being convinced that the change is safe in all theoretical cases. On more wrinkle. Shinylive is actually a good example of how query parameters can be tricky to untangle: Shinylive itself makes use of query parameters that should be separated from the app's parameters. Those query parameters aren't widely used, but it points at the fact that simply passing query and hash components from the parent window down to the iframe carries inherent ambiguity. I appreciate you sharing your snippet of JavaScript. That certainly seems like a very good solution to the problem, especially when you're certain that doing so won't be affected by the parent page's state. |
Ah, I should have known that you all are already discussing this! I never even thought about situations where multiple shinylive apps are present on the same page, so now I totally understand the apprehension to change this. I guess I'll just stick with the hacks I've developed for the time being. Speaking of which, in case anyone else comes across this issue...the $(function() {
$(window.parent).on('hashchange', function (e) {
$('#currentHash').val(window.parent.location.hash).change();
});
}); Then you just need to add an observer for that input. |
updateQueryString()
(orsession$updateQueryString
) ultimately callswindow.history.replaceState()
orwindow.history.pushState()
. However, when usingshinylive
the app is served as an iframe, sowindow
in this case refers to the iframe, not the parent window. Therefore, neither of these calls works andupdateQueryString()
does nothing. I've found the following works instead:The MDN docs state that "If a window does not have a parent, its parent property is a reference to itself." Therefore. changing the typescript code to just use
window.parent
instead ofwindow
should fix this problem, regardless of whether you are usingshinylive
or not.The text was updated successfully, but these errors were encountered: