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

404 causes DOMException #188

Closed
iamdriz opened this issue Feb 23, 2021 · 9 comments · Fixed by #483
Closed

404 causes DOMException #188

iamdriz opened this issue Feb 23, 2021 · 9 comments · Fixed by #483

Comments

@iamdriz
Copy link

iamdriz commented Feb 23, 2021

I'm using the latest version of Turbo (beta 4 at the time of writing) and I've noticed that when you hit a 404 page it causes the following error in the console:

Uncaught DOMException: Failed to execute 'define' on 'CustomElementRegistry': the name "turbo-frame" has already been used with this registry

This only happens when hitting a 404 from another link... if you refresh the non existent page the error doesn't happen.

@iamdriz
Copy link
Author

iamdriz commented Feb 23, 2021

If it helps here's a screenshot of exactly what happens in the console when the navigation to the non existent page happens:

image

@morindo
Copy link

morindo commented Mar 12, 2021

I'm having the same problem using 7.0.0-beta.4 configured with Webpack in ASP.NET Core. Response with 404 and 500 status code seems to reload turbo.

@clinejj
Copy link

clinejj commented May 6, 2021

This looks to be related to #104 and a similar issue from Turbolinks: turbolinks/turbolinks#179

Essentially Turbo handles 404/500 pages differently, and ends up re-rendering the page and initializing itself twice which leads to these errors. Unfortunately, the monkey patch from the issue above doesn't work on Turbo (or I can't get it to work at least)

@clinejj
Copy link

clinejj commented Sep 24, 2021

I opened hotwired/turbo-rails#249 as this seems to be more of an issue with turbo-rails than Turbo, and the specific use case we're able to replicate on is using a custom error controller that has the same layout as our main application which includes turbo. Because the ErrorRender in Turbo reloads both the body and head, it leads to turbo-rails and turbo being initialized twice. It seems that Turbo is protected from this (here), but turbo-rails is not.

@tydoo
Copy link

tydoo commented Oct 14, 2021

Same problem with 7.0.1

@markdavies
Copy link

I am seeing the same issue in a non-Rails setup

@kmmbvnr
Copy link

kmmbvnr commented Nov 2, 2021

I fixed this with data-turbo-eval="false" on the script tag with turbo bundle

<script src="{% static 'viewflow/js/turbo.es5-umd.js' %}" data-turbo-eval="false"></script>

@denydias
Copy link

denydias commented Apr 19, 2022

This one is indeed a showstopper for anything handling 4xx and 5xx errors.

As @clinejj observed above, the monkey patch didn't work and it'll never work with Turbo. It turns out that HttpRequest class was removed altogether. But rather than what he also pointed out, it's not only turbo-rails related. Also, it's not limited to turbo-frame and turbo-stream as PR #483 address. My laravel project also suffers with the same 4xx and 5xx handling issues, while having no turbo-frame nor turbo-stream implemented. For my particular case, turbolinks HttpRequest monkey patch provides quite an easy and reliable fix.

It would be really nice from Turbo devs if they could elaborate a bit on the reasoning behind HttpRequest removal. It would be even nicer from their part if a workaround could be provided... It doesn't even need to be funcional code tho. A shallow overview would suffice for devs like us to figure out the rest.

@kidlj
Copy link

kidlj commented Jun 12, 2022

I'm having the same problem with "@hotwired/turbo": "^7.1.0", not on Rails framework.

After changing

import "@hotwired/turbo"

from index.js to

if (!window.Turbo) {
	require("@hotwired/turbo")
}

The problem is gone, but the 404 page would flash a bit, not as smooth as normal pages.

@dhh dhh closed this as completed in #483 Jun 19, 2022
bep added a commit to bep/turbo that referenced this issue Sep 13, 2022
This is discussed in detail several places, e.g:
hotwired#188 (comment)
bep added a commit to bep/turbo that referenced this issue Sep 13, 2022
This is discussed in detail several places, e.g:
hotwired#188 (comment)
bep added a commit to bep/turbo that referenced this issue Sep 13, 2022
This is discussed in detail several places, e.g:
hotwired#188 (comment)
bep added a commit to bep/turbo that referenced this issue Sep 13, 2022
This is discussed in detail several places, e.g:
hotwired#188 (comment)
bep added a commit to bep/turbo that referenced this issue Sep 13, 2022
This is discussed in detail several places, e.g:
hotwired#188 (comment)
bep added a commit to bep/turbo that referenced this issue Sep 13, 2022
This is discussed in detail several places, e.g:
hotwired#188 (comment)
bep added a commit to bep/turbo that referenced this issue Sep 13, 2022
This is discussed in detail several places, e.g:
hotwired#188 (comment)
bep added a commit to bep/turbo that referenced this issue Mar 7, 2023
This is discussed in detail several places, e.g:
hotwired#188 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

8 participants