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

Turbo Streams: Preserve permanent elements #688

Merged
merged 2 commits into from Sep 13, 2022

Conversation

seanpdoyle
Copy link
Contributor

Closes #623

Refactor the Snapshot implementation to make the permanent element
finding code re-usable outside that module.

Then, introduce the StreamMessageRenderer class, and re-use that code.

The StreamMessageRenderer class also implements BardoDelegate, and
relies on Bardo.preservingPermanentElements to manage elements across
their <turbo-stream> rendering lifespan.

Closes hotwired#623

Refactor the `Snapshot` implementation to make the permanent element
finding code re-usable outside that module.

Then, introduce the `StreamMessageRenderer` class, and re-use that code.

The `StreamMessageRenderer` class also implements `BardoDelegate`, and
relies on `Bardo.preservingPermanentElements` to manage elements across
their `<turbo-stream>` rendering lifespan.
```
1) [firefox] › navigation_tests.ts:161:1 › test following a same-origin unannotated link inside a data-turbo=false container

    page.click: Target closed
    =========================== logs ===========================
    waiting for selector "#same-origin-unannotated-link-inside-false-container"
      selector resolved to visible <a href="/src/tests/fixtures/one.html" id="same-ori…>Same-origin unannotated link inside data-turbo=fa…</a>
    attempting click action
      waiting for element to be visible, enabled and stable
      element is visible, enabled and stable
      scrolling into view if needed
    ============================================================

      160 |
      161 | test("test following a same-origin unannotated link inside a data-turbo=false container", async ({ page }) => {
    > 162 |   page.click("#same-origin-unannotated-link-inside-false-container")
          |        ^
      163 |   await nextBody(page)
      164 |   assert.equal(pathname(page.url()), "/src/tests/fixtures/one.html")
      165 |   assert.equal(await visitAction(page), "load")

        at /home/runner/work/turbo/turbo/src/tests/functional/navigation_tests.ts:162:8
```

When driving tests that navigate `[data-turbo="false"]` anchors, replace
the bespoke `await nextBody(page)` helper with Playwright's built-in and
more predictable [Page.waitForEvent("load")][], since the entire
document will navigate.

[Page.waitForEvent("load")]: https://playwright.dev/docs/api/class-page#page-wait-for-event
@dhh dhh merged commit cf3d726 into hotwired:main Sep 13, 2022
@seanpdoyle seanpdoyle deleted the fix-issue-623 branch September 13, 2022 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Turbo Stream operations ignore [data-turbo-permanent]
2 participants