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

Return Promise<void> from Turbo.visit #650

Merged
merged 1 commit into from
Jul 28, 2022

Conversation

seanpdoyle
Copy link
Contributor

When consumer applications navigate through the Turbo.visit, return a
Promise<void> that will resolve when the visit is complete.

If a visit fails or is cancelled, the Promise will be rejected.

To achieve this behavior, extract the ResolvingFunctions<T> type
from the Renderer class into the shared src/core/types.ts module.
Following the pattern established by Renderer instances, add a
promise: Promise property to the Visit class, and use that Promise
to assign a resolvingFunctions: ResolvingFunctions<void> property to
make the underlying resolve() and reject() calls available to the
Visit.

When a Visit completes successfully, call
this.resolvingFunctions.resolve(). When it fails or is canceled from
the outside, call this.resolvingFunctions.reject().

When consumer applications navigate through the `Turbo.visit`, return a
`Promise<void>` that will resolve when the visit is complete.

If a visit fails or is cancelled, the `Promise` will be rejected.

To achieve this behavior, extract the `ResolvingFunctions<T>` type
from the `Renderer` class into the shared `src/core/types.ts` module.
Following the pattern established by `Renderer` instances, add a
`promise: Promise` property to the `Visit` class, and use that `Promise`
to assign a `resolvingFunctions: ResolvingFunctions<void>` property to
make the underlying `resolve()` and `reject()` calls available to the
`Visit`.

When a `Visit` completes successfully, call
`this.resolvingFunctions.resolve()`. When it fails or is canceled from
the outside, call `this.resolvingFunctions.reject()`.
@seanpdoyle seanpdoyle force-pushed the turbo-visit-promise branch from b935c18 to 6921676 Compare July 27, 2022 20:25
@dhh dhh merged commit aeeaae8 into hotwired:main Jul 28, 2022
@seanpdoyle seanpdoyle deleted the turbo-visit-promise branch July 28, 2022 21:45
dhh pushed a commit that referenced this pull request Sep 19, 2022
Since #650, errors are present in the console whenever initiating a
visit causes cancellation of the previous visit.

Reported in:
- #706
- #716

Reverting until a solution is found for the errors.

This reverts commit aeeaae8.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants