mirror of
https://github.com/gristlabs/grist-core.git
synced 2024-10-27 20:44:07 +00:00
allow Grist front-end to function when location history is unavailable (#596)
* allow Grist front-end to function when location history is unavailable When the Grist front-end is embedded in an iframe, using a srcdoc attribute, history.pushState and similar methods are unavailable. Currently, that makes it impossible to navigate between Grist pages, since an access error is thrown (behavior may be browser dependent). With this change, navigation succeeds. * give unrelated possibly slow test a little more time
This commit is contained in:
parent
ab6807c342
commit
f0b9e1f7e9
@ -77,6 +77,7 @@ export class UrlState<IUrlState extends object> extends Disposable {
|
||||
|
||||
if (samePage) {
|
||||
await this._stateImpl.delayPushUrl(prevState, newState);
|
||||
try {
|
||||
if (options.replace) {
|
||||
this._window.history.replaceState(null, '', newUrl);
|
||||
} else {
|
||||
@ -84,6 +85,15 @@ export class UrlState<IUrlState extends object> extends Disposable {
|
||||
}
|
||||
// pushState/replaceState above do not trigger 'popstate' event, so we call loadState() manually.
|
||||
this.loadState();
|
||||
} catch (e) {
|
||||
// If we fail, we may be in a context where Grist doesn't have
|
||||
// control over history, e.g. an iframe with srcdoc. Go ahead
|
||||
// and apply the application state change (e.g. switching to a
|
||||
// different Grist page). The back button won't work, but what
|
||||
// it should do in an embedded context is full of nuance anyway.
|
||||
log.debug(`pushUrl failure: ${e}`);
|
||||
this.state.set(this._stateImpl.decodeUrl(new URL(newUrl)));
|
||||
}
|
||||
} else {
|
||||
this._window._urlStateLoadPage!(newUrl);
|
||||
}
|
||||
|
BIN
test/fixtures/docs/SelectBySummary.grist
vendored
BIN
test/fixtures/docs/SelectBySummary.grist
vendored
Binary file not shown.
@ -4,7 +4,7 @@ import * as gu from 'test/nbrowser/gristUtils';
|
||||
import {server, setupTestSuite} from 'test/nbrowser/testUtils';
|
||||
|
||||
describe('SelectByRefList', function() {
|
||||
this.timeout(60000);
|
||||
this.timeout(80000);
|
||||
setupTestSuite();
|
||||
addToRepl('gu2', gu);
|
||||
gu.bigScreen();
|
||||
|
Loading…
Reference in New Issue
Block a user