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

Dispatch turbo:fetch-request-error on eager/lazy-loaded frame #768

Open
nate-at-gusto opened this issue Oct 18, 2022 · 2 comments
Open

Dispatch turbo:fetch-request-error on eager/lazy-loaded frame #768

nate-at-gusto opened this issue Oct 18, 2022 · 2 comments

Comments

@nate-at-gusto
Copy link

#685 seems to have added this event to most places, but I think one place it could fire but doesn't currently is on an eager or lazy-loaded frame. Frames with src attributes don't fire this event when their fetch request fails on initial page load.

@seanpdoyle
Copy link
Contributor

@nate-at-gusto thank you for opening this issue!

I've tried to reproduce the behavior you're describing locally in the test suite, but I'm having trouble writing a failing test.

So far, I've tried this:

diff --git a/src/tests/fixtures/frames.html b/src/tests/fixtures/frames.html
index c308995..e7087c9 100644
--- a/src/tests/fixtures/frames.html
+++ b/src/tests/fixtures/frames.html
@@ -1,5 +1,5 @@
 <!DOCTYPE html>
-<html id="html" data-skip-event-details="turbo:click turbo:before-render">
+<html id="html" data-skip-event-details="turbo:click turbo:before-render turbo:fetch-request-error">
   <head>
     <meta charset="utf-8">
     <title>Frame</title>
@@ -119,6 +119,10 @@
       <a id="frame-part" href="/src/tests/fixtures/frames/part.html">Load #part</a>
     </turbo-frame>
 
+    <turbo-frame id="menu" src="/src/tests/fixtures/frames/preloading.html" disabled>
+      Disabled #menu
+    </turbo-frame>
+
     <a id="outer-frame-link" href="/src/tests/fixtures/frames/frame.html" data-turbo-frame="frame">Outer frame link</a>
     <form data-turbo-frame="frame" method="get" action="/src/tests/fixtures/frames/frame.html">
       <input id="outer-frame-submit" type="submit" value="Outer form submit">
diff --git a/src/tests/functional/frame_tests.ts b/src/tests/functional/frame_tests.ts
index e281156..809eb76 100644
--- a/src/tests/functional/frame_tests.ts
+++ b/src/tests/functional/frame_tests.ts
@@ -387,6 +387,13 @@ test("test removing [disabled] attribute from eager-loaded frame navigates it",
   await nextEventOnTarget(page, "frame", "turbo:before-fetch-request")
 })
 
+test("test eager-loading a frame emits fetch-request-error event when offline", async ({ page }) => {
+  await page.context().setOffline(true)
+  await page.locator("turbo-frame#menu").evaluate((menu) => menu.removeAttribute("disabled"))
+
+  await nextEventOnTarget(page, "menu", "turbo:fetch-request-error")
+})
+
 test("test evaluates frame script elements on each render", async ({ page }) => {
   assert.equal(await frameScriptEvaluationCount(page), undefined)

The test passes without any implementation changes. Are there any details that I've missed in the test harness or exercise?

@nate-at-gusto
Copy link
Author

If it helps, the console error message shows that the failed request comes from a visit's FetchRequest perform:
Screenshot 2023-03-16 at 11 08 27 AM
Screenshot 2023-03-16 at 11 09 45 AM

This is reproducible in browser by blocking the request url for the initial load of the frame, e.g. in DevTool's Network tab.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants