Support FrameElement.reload()
without an initial [src]
attribute
#1004
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The problem
If a
<turbo-frame>
element is rendered without a[src]
attribute,calls to
.reload()
will have no effect. If a<turbo-frame>
is to beits own browsing context, it should be able to apply its current
location (that is, it's owning document's current location) to its
browsing context.
For example, if a page has a
<turbo-frame>
element that contains textthat's typically updated by a Web Socket-delivered
<turbo-stream>
, itmight be useful to gracefully degrade to periodic long-polling if
that Web Socket connection were to fail. That might involve something
like a
reload
Stimulus controller with a delay:The fact that the
<turbo-frame id="dynamic-data">
element doesn't havea
[src]
attribute shouldn't prevent the page from being able tore-fetch its content.
The solution
When
FrameElement.reload()
is invoked, it delegates to its delegateinstance's
sourceURLReloaded()
method. In all cases,FrameElement.delegate
is an instance ofFrameController
.This commit extends the
FrameController.sourceURLReloaded()
implementation to set the element's
[src]
attribute to the element'sbaseURI value, which sets off the usual attribute change listeners
and
<turbo-frame>
navigation logic.