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.
Type of PR (feature, enhancement, bug fix, etc.)
Enhancement
Description
This PR proposes to return the
isolate: true
option passed to the SR initializer, with this being set as the default value for new projects.#317 broke compatibility with previous versions of the library by making it impossible for multiple tabs to be open and receiving the same CableReady operation broadcasts. This is because the promise associated with the Reflex only existed in the tab that created the Reflex. Any additional tabs would show failing reflex messages.
This PR restored the ability for multiple tabs to receive the same updates. I did this by abstracting the promise creation into a function and adding logic to the ActionCable subscriber to create a new proxy promise from the
details.stimulusReflex
object on the CableReady broadcast.I had to resurrect my xPath processing code from roughly a year ago! I can use xPath to grab things in this PR because it all happens before any CableReady operations are initiated.
Three things have been added to the Reflex request payload to support this functionality:
Using this data, I was able to dynamically reattach to the correct controller instance for the Reflex.😅
I changed the success/error logging slightly so that on non-originating tabs, the debug output shows
CLONED
instead of a Reflex duration, because there's no way to know when the request started on the originating tab without sending it to the server, and I thought seeing a visual reminder that this is not the original Reflex would be more useful.All callback methods and lifecycle events are supported. There is, however, no reasonable or logical way to attach a callback to the cloned promise because the whole point of the promise is that it's initiated by the calling tab. I will need to find a simple way to explain this in the documentation.
Errata
permanent_attribute_name
topermanentAttributeName
Why should this be added
While most developers will want their Reflex operations contained within the browser tab in which they originate, we want to allow flexibility for those who think a little differently.
Checklist