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

Wrap bespoke state plugin's state updation in try-catch #160

Merged
merged 2 commits into from
Sep 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [Unreleased]

### Fixed

- Safari prevents moving slide after too many navigations ([#158](https://github.com/marp-team/marp-cli/issues/158), [#160](https://github.com/marp-team/marp-cli/pull/160))

## v0.14.1 - 2019-09-15

### Fixed
Expand Down
26 changes: 19 additions & 7 deletions src/templates/bespoke/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,16 @@ const coerceInt = (ns: string) => {
export default function bespokeState(opts: BespokeStateOption = {}) {
const options: BespokeStateOption = { history: true, ...opts }

const updateState = (...args: Parameters<typeof history['pushState']>) =>
options.history ? history.pushState(...args) : history.replaceState(...args)
const updateState = (...args: Parameters<typeof history['pushState']>) => {
try {
options.history
? history.pushState(...args)
: history.replaceState(...args)
} catch (e) {
// Safari may throw SecurityError by replacing state 100 times per 30 seconds.
console.error(e)
}
}

return deck => {
let internalNavigation = true
Expand Down Expand Up @@ -77,11 +85,15 @@ export default function bespokeState(opts: BespokeStateOption = {}) {
const params = new URLSearchParams(location.search)
params.delete('f')

history.replaceState(
null,
document.title,
generateURLfromParams(params)
)
try {
history.replaceState(
null,
document.title,
generateURLfromParams(params)
)
} catch (e) {
console.error(e)
}
})
)

Expand Down