I have a case in application where I need to redirect user to page with different layout (and different CSS / JS) after form submission. That redirection works but Turbo sends two requests for new page
First one is XHR
Another one is for full reload - because Turbo decides that changed
The problem is that for short period of time - (1) is rendered. And then replaced by (2). Which is not noticeable by users but Capybara / Webdriver raises following error making test flaky
unknown error: unhandled inspector error: {"code":-32000,"message":"Node with given id does not belong to the document"}
I can add “data-turbo=false” to form but was just wondering - is that the only option?
Looking at this from the Capybara aspect only: this error sounds like a timing issue inside the test, which can be solved by expecting a change on the page with one of Capybara’s built-in matchers. They use a wait-retry-until mechanism under the hood, so they’ll wait until the final expected state is reached.
For example, expect the text of a flash message:
# ... submit form ...
expect(page).to have_content("Thing was successfully updated.")
Make sure there’s no within wrapped around the expectation which could hold on to DOM elements that get removed.
I know about waiting behaviour. But you see - this page is the same both times. So it might happen that between “find” and “act” page is reloaded rendering, the same DOM visually but different.