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

Morph with ignoreActiveValue: true #1141

Merged
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"chai": "~4.3.4",
"eslint": "^8.13.0",
"express": "^4.18.2",
"idiomorph": "^0.3.0",
"idiomorph": "https://github.com/bigskysoftware/idiomorph.git",
"multer": "^1.4.2",
"rollup": "^2.35.1"
},
Expand Down
1 change: 1 addition & 0 deletions src/core/drive/morph_renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export class MorphRenderer extends Renderer {
this.isMorphingTurboFrame = this.#isFrameReloadedWithMorph(currentElement)

Idiomorph.morph(currentElement, newElement, {
ignoreActiveValue: true,
morphStyle: morphStyle,
callbacks: {
beforeNodeAdded: this.#shouldAddElement,
Expand Down
7 changes: 7 additions & 0 deletions src/tests/fixtures/page_refresh.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ <h3>Element with Stimulus controller</h3>
<input>
</div>

<form method="get" data-turbo-action="replace" oninput="this.requestSubmit()">
<label>
Search
<input name="query">
</label>
<button>Form with params to refresh the page</button>
</form>
<p><a id="replace-link" data-turbo-action="replace" href="/src/tests/fixtures/page_refresh.html?param=something">Link with params to refresh the page</a></p>
<p><a id="link" href="/src/tests/fixtures/one.html">Link to another page</a></p>

Expand Down
25 changes: 22 additions & 3 deletions src/tests/functional/page_refresh_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
nextEventNamed,
nextEventOnTarget,
noNextEventOnTarget,
noNextEventNamed
noNextEventNamed,
getSearchParam
} from "../helpers/page"

test("renders a page refresh with morphing", async ({ page }) => {
Expand Down Expand Up @@ -81,6 +82,24 @@ test("renders a page refresh with morphing when the paths are the same but searc
await nextEventNamed(page, "turbo:render", { renderMethod: "morph" })
})

test("renders a page refresh with morphing when the GET form paths are the same but search params are diferent", async ({ page }) => {
await page.goto("/src/tests/fixtures/page_refresh.html")

const input = page.locator("form[method=get] input[name=query]")

await input.fill("Search")
await nextEventNamed(page, "turbo:render", { renderMethod: "morph" })

await expect(input).toBeFocused()
expect(getSearchParam(page.url(), "query")).toEqual("Search")

await input.press("?")
await nextEventNamed(page, "turbo:render", { renderMethod: "morph" })

await expect(input).toBeFocused()
expect(getSearchParam(page.url(), "query")).toEqual("Search?")
})

test("doesn't morph when the turbo-refresh-method meta tag is not 'morph'", async ({ page }) => {
await page.goto("/src/tests/fixtures/page_refresh_replace.html")

Expand Down Expand Up @@ -181,12 +200,12 @@ test("it preserves focus across morphs", async ({ page }) => {

const input = await page.locator("#form input[type=text]")

await input.fill("Discard me")
await input.fill("Preserve me")
await input.press("Enter")
await nextEventNamed(page, "turbo:render", { renderMethod: "morph" })

await expect(input).toBeFocused()
await expect(input).toHaveValue("")
await expect(input).toHaveValue("Preserve me")
})

test("it preserves focus and the [data-turbo-permanent] element's value across morphs", async ({ page }) => {
Expand Down
5 changes: 2 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1865,10 +1865,9 @@ iconv-lite@0.4.24:
dependencies:
safer-buffer ">= 2.1.2 < 3"

idiomorph@^0.3.0:
"idiomorph@https://github.com/bigskysoftware/idiomorph.git":
version "0.3.0"
resolved "https://registry.yarnpkg.com/idiomorph/-/idiomorph-0.3.0.tgz#f6675bc5bef1a72c94021e43141a3f605d2d6288"
integrity sha512-UhV1Ey5xCxIwR9B+OgIjQa+1Jx99XQ1vQHUsKBU1RpQzCx1u+b+N6SOXgf5mEJDqemUI/ffccu6+71l2mJUsRA==
resolved "https://github.com/bigskysoftware/idiomorph.git#b5115add9f7ab04c04af0624385540dff04e0735"

ieee754@^1.1.13:
version "1.2.1"
Expand Down
Loading