-
Notifications
You must be signed in to change notification settings - Fork 951
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* remove replaceRootHistory Relates to: #3529 `replaceRootHistory` was initially added by @josevalim in 36edb48, but lost its purpose after less than three months with 04aaedc removing the only call that would actually set `root: true` in the history state. Me not knowing what `root: true` is supposed to do reused replaceRootHistory in #3335, reintroducing the case where `root: true`` is set in the history state. While #3335 was reverted later due to issues (#3508), I reworked the back/forward navigation problem in #3539, which again used `replaceRootHistory`. As `root: true` would now be set in the history, we'd call `replaceRootHistory` on live navigation. The problem is that it was setting `type: "patch"` in the history, which leads to LiveView assuming that it can patch when navigating using popstate, while the actual navigation was `type: "navigate"`. After looking into it, I don't really see a reason for replaceRootHistory to exist any more. * add e2e test for #3529 * update changelog
- Loading branch information
Showing
6 changed files
with
80 additions
and
19 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,23 @@ | ||
defmodule Phoenix.LiveViewTest.E2E.Issue3529Live do | ||
# https://github.com/phoenixframework/phoenix_live_view/issues/3529 | ||
|
||
use Phoenix.LiveView | ||
|
||
alias Phoenix.LiveView.JS | ||
|
||
def mount(_params, _session, socket) do | ||
{:ok, assign(socket, :mounted, DateTime.utc_now())} | ||
end | ||
|
||
def handle_params(_params, _uri, socket) do | ||
{:noreply, assign(socket, :next, :rand.uniform())} | ||
end | ||
|
||
def render(assigns) do | ||
~H""" | ||
<h1>Mounted at {@mounted}</h1> | ||
<.link navigate={"/issues/3529?param=#{@next}"}>Navigate</.link> | ||
<.link patch={"/issues/3529?param=#{@next}"}>Patch</.link> | ||
""" | ||
end | ||
end |
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,45 @@ | ||
const {test, expect} = require("../../test-fixtures") | ||
const {syncLV} = require("../../utils") | ||
|
||
const pageText = async (page) => await page.evaluate(() => document.querySelector("h1").innerText) | ||
|
||
// https://github.com/phoenixframework/phoenix_live_view/issues/3529 | ||
// https://github.com/phoenixframework/phoenix_live_view/pull/3625 | ||
test("forward and backward navigation is handled properly (replaceRootHistory)", async ({page}) => { | ||
await page.goto("/issues/3529") | ||
await syncLV(page) | ||
|
||
let text = await pageText(page) | ||
await page.getByRole("link", {name: "Navigate"}).click() | ||
await syncLV(page) | ||
|
||
// navigate remounts and changes the text | ||
expect(await pageText(page)).not.toBe(text) | ||
text = await pageText(page) | ||
|
||
await page.getByRole("link", {name: "Patch"}).click() | ||
await syncLV(page) | ||
// patch does not remount | ||
expect(await pageText(page)).toBe(text) | ||
|
||
// now we go back (should be patch again) | ||
await page.goBack() | ||
await syncLV(page) | ||
expect(await pageText(page)).toBe(text) | ||
|
||
// and then we back to the initial page and use back/forward | ||
// this should be a navigate -> remount! | ||
await page.goBack() | ||
await syncLV(page) | ||
expect(await pageText(page)).not.toBe(text) | ||
|
||
// navigate | ||
await page.goForward() | ||
await syncLV(page) | ||
text = await pageText(page) | ||
|
||
// now back again (navigate) | ||
await page.goBack() | ||
await syncLV(page) | ||
expect(await pageText(page)).not.toBe(text) | ||
}) |