-
Notifications
You must be signed in to change notification settings - Fork 435
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
Defensively create custom turbo elements #483
Conversation
There are instances when turbo attempts to create the frame and stream elements when they have already been registered. This is easily reproducible in development when using webpacker by following these steps: * Make a change to any file that webpacker compiles. * Click a turbo enabled link. * Boom. When Turbo replaces the page it appears as if it reloads the Turbo library and attempts to create the custom elements again. I have also observed this behavior in my production app via my exception monitoring service, but have been unable to reproduce this behavior in production on my own. This change simply checks for the existence of the custom element prior to to attempting to define it. The `get` method used here explicitly returns `undefined` when the element does not yet exist so it is safe to use the strict equality operator here. Reference: https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry/get
Update: This happens reliably in production when the webpack bundle has changed (after a deploy) and a turbo enabled link is clicked. |
Yet another update: After updating my application to use jsbundling-rails and esbuild I am no longer seeing this error on deploys (or at all for that matter). |
Is that with or without this patch with your update to jsbundling-rails? |
@t27duck Without the patch. I honestly don't know why. 🤷 |
We can also reproduce this in production where on deploy, the bundle changes and this error is triggered after clicking on any turbo link. Would love to see this merged. |
* main: Allow frames to scroll smoothly into view (hotwired#607) Export Type declarations for `turbo:` events (hotwired#452) Add .php as a valid isHTML extension (hotwired#629) Add original click event to 'turbo:click' details (hotwired#611) Drive Browser tests with `playwright` (hotwired#609) Allow Turbo Streams w/ GET via `data-turbo-stream` (hotwired#612) Only update history when Turbo visit is renderable (hotwired#601) Support development ChromeDriver version overrides (hotwired#606) Turbo stream source (hotwired#415) Expose Frame load state via `[complete]` attribute (hotwired#487) fix(ie/edge): form.method='delete', raises Invalid argument. (hotwired#586) Do not declare global types/constants (hotwired#524) Defensively create custom turbo elements (hotwired#483) Use `replaceChildren` in StreamActions.update (hotwired#534)
There are instances when turbo attempts to create the frame and stream
elements when they have already been registered. This is easily
reproducible in development when using webpacker by following these steps:
When Turbo replaces the page it appears as if it reloads the Turbo
library and attempts to create the custom elements again. I have also
observed this behavior in my production app via my exception monitoring
service, but have been unable to reproduce this behavior in production
on my own.
This change simply checks for the existence of the custom element prior
to to attempting to define it. The
get
method used here explicitlyreturns
undefined
when the element does not yet exist so it is safe touse the strict equality operator here. Reference:
https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry/get
Fixes #188