Skip to content

Commit

Permalink
skip reloads
Browse files Browse the repository at this point in the history
  • Loading branch information
martrapp committed Sep 8, 2024
1 parent 444ab59 commit c15cf38
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/lemon-penguins-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@vtbag/element-crossing': patch
---

Ensures that state does not cross full page *reloads*.
2 changes: 1 addition & 1 deletion .github/workflows/run-build.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

name: Just Build
name: Build

on:
workflow_dispatch:
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[⭐️Please star to support this work⭐️](https://github.com/vtbag/element-crossing)

# 🚸 ElementCrossing

Transfer selected element state across cross-document view transitions.
Expand Down
17 changes: 14 additions & 3 deletions src/vanilla.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,23 @@ function pageSwap() {
}
}



function pageReveal() {
if (
performance?.navigation?.type === 1 ||
// @ts-expect-error
('navigation' in self && self.navigation?.navigationType === 'reload')
) {
return;
}
let values;
if (self.crossingStorage) {
values = self.crossingStorage.getItem('@vtbag/element-crossing') ?? [];
let storage;
if ((storage = self.crossingStorage)) {
values = storage.getItem('@vtbag/element-crossing') ?? [];
} else {
values = JSON.parse(top!.sessionStorage.getItem('@vtbag/element-crossing') ?? '[]');
storage = top!.sessionStorage;
values = JSON.parse(storage.getItem('@vtbag/element-crossing') ?? '[]');
}
restore(values);
}
Expand Down

0 comments on commit c15cf38

Please sign in to comment.