Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Propagate pushState/replaceState inside worker (#172)
* feat: forward history.pushState/replaceState calls to worker * fix: keep passing doc.baseURI in LocationUpdateData * feat: add basic PopStateEvent and HashChangeEvent implementation * refactor: remove popstate/hashchange event handlers from worker-location * refactor: simplify logic responsible for preventing history change propagation back to main thread * refactor: remove duplicated declaration * test: propagate pushState and replaceState inside worker * fix: reset $propagateHistoryChange$ even after pushState or replaceState throws * test: assign originalPushState right before patching it
- Loading branch information
1 parent
a03255b
commit 5b90408
Showing
7 changed files
with
160 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { LocationUpdateData, LocationUpdateType, WebWorkerEnvironment } from "../types"; | ||
|
||
export function forwardLocationChange($winId$: number, env: WebWorkerEnvironment, data: LocationUpdateData) { | ||
const history = env.$window$.history; | ||
|
||
switch (data.type) { | ||
case LocationUpdateType.PushState: { | ||
env.$propagateHistoryChange$ = false; | ||
try { | ||
history.pushState(data.state, '', data.newUrl) | ||
} catch (e) {} | ||
env.$propagateHistoryChange$ = true; | ||
break; | ||
} | ||
case LocationUpdateType.ReplaceState: { | ||
env.$propagateHistoryChange$ = false; | ||
try { | ||
history.replaceState(data.state, '', data.newUrl) | ||
} catch (e) {} | ||
env.$propagateHistoryChange$ = true; | ||
break; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5b90408
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
partytown – ./
partytown.vercel.app
partytown-git-main-builder-io.vercel.app
partytown.builder.io
partytown-builder-io.vercel.app