Skip to content
Open
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
29 changes: 29 additions & 0 deletions e2e-tests/persistence.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,32 @@ test("should not add a history entry for each state change", async ({
await page.goForward();
await expect(esquerySelectorInput).toHaveValue("Identifier");
});

test("should load state when the URL hash changes without a page reload", async ({
page,
}) => {
await page.goto("/");

const codeEditor = page.getByRole("textbox", {
name: "Code Editor",
exact: true,
});

const firstCode = "const first = 1;";
await codeEditor.fill(firstCode);
await expect.poll(() => getPersistedJavaScriptCode(page)).toBe(firstCode);
const firstHash = new URL(page.url()).hash;

const secondCode = "const second = 2;";
await codeEditor.fill(secondCode);
await expect.poll(() => getPersistedJavaScriptCode(page)).toBe(secondCode);

await page.goto(`/${firstHash}`);
await expect(codeEditor).toContainText(firstCode);

await page.goBack();
await expect(codeEditor).toContainText(secondCode);

await page.goForward();
await expect(codeEditor).toContainText(firstCode);
});
4 changes: 4 additions & 0 deletions src/hooks/use-explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,3 +307,7 @@ export const useExplorer = create<ExplorerState>()(
),
),
);

window.addEventListener("hashchange", () => {
useExplorer.persist.rehydrate();
});
Loading