tower / commit
fix(app): a shared #view= link was erased before it was read
src/ui/app.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/ui/app.ts b/src/ui/app.ts index 0bb85e2..4d74a49 100644 --- a/src/ui/app.ts +++ b/src/ui/app.ts @@ -90,8 +90,15 @@ export class App { this.store.subscribe(() => this.render()) this.map.fit() this.readHash() + /** + * Decide the view BEFORE the first render. render() rewrites the hash from the + * current state, so reading `#view=` afterwards reads a hash this very + * constructor has already erased — which quietly broke every shared link that + * named a view. + */ + this.view = this.initialView() this.render() - void this.setView(this.initialView()) + void this.setView(this.view) } // ----------------------------------------------------------------- views @@ -219,6 +226,11 @@ export class App { private readHash(): void { const params = new URLSearchParams(location.hash.slice(1)) + // A hash edited in place fires hashchange rather than reloading, so the view + // has to be honoured here too — otherwise `#view=` only ever works on a cold + // load, and following one link from another quietly ignores it. + const view = params.get('view') + if (isView(view) && view !== this.view) void this.setView(view) const id = params.get('place') if (id && this.store.get(id)) { this.selectedId = id