Skip to content

[WIP] [Live] Make Ajax calls happen in serial, with "queued" changes #466

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

Merged
merged 5 commits into from
Sep 27, 2022

Conversation

weaverryan
Copy link
Member

@weaverryan weaverryan commented Sep 19, 2022

Q A
Bug fix? yes
New feature? yes
Tickets None
License MIT

Hi!

Consider the following situation:

A) Model update is made: Ajax call starts
B) An action is triggered BEFORE the Ajax call from (A) finishes.

Previously, we would start a 2nd Ajax call for (B) before the Ajax call from (A) finished... meaning two Ajax calls were happening at the same time. There are a few problems with this: (i) Ajax call (B) is missing any potential data changes from Ajax call (A) and (i) complexity of multiple things loading at once, and potentially finishing in a different order.

This PR simplifies things, which matches Livewire's behavior anyways. Now, the action from (B) will WAIT until the Ajax call from (A) finishes and THEN start. In fact, while an Ajax call is being made, all changes (potentially multiple model updates or actions) will be "queued" and then all set at once on the next request.

TODO:

  • Update the backend: for POST requests, the "data" was moved under a data key in JSON. Previously the entire body was the "data".
  • Update the backend: for POST/action requests, action "arguments" were moved from query parameters to an args key in the JSON.
  • Frontend: add tests for the batch action Ajax calls
  • Update the backend: a new fake /batch action needs to be added that can handle multiple actions at once
  • A new updatedModels is sent on the ajax requests. If the signature fails, use this to give a better error message about what readonly properties were just modified. (in fact, this is the only purpose of sending this new field to the backend at this time).
  • Pass a includeUpdatedModels value to the Stimulus controller ONLY when in dev mode. For consistency, we will always pass the updatedModels in our Ajax requests, though this is intended to be "internal" and we won't use it other than to throw better errors.
  • (Optional) If the backend has an unexpected exception (i.e. 5xx or maybe some 4xx where we mark that this is a problem we should show the developer), then render the entire HTML exception page (in dev mode only) so the user can see the error. Done in [Live] Rendering any errors in a simple modal #467

Cheers!

@weaverryan weaverryan merged commit e71e305 into symfony:2.x Sep 27, 2022
weaverryan added a commit that referenced this pull request Sep 27, 2022
… sync bug & auto-setting data-model values (weaverryan)

This PR was merged into the 2.x branch.

Discussion
----------

[Waiting][Live] Doc'ing how to set values via Js, select sync bug & auto-setting data-model values

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| Tickets       | Fixes #469 Fixes #473
| License       | MIT

This does 3 unrelated things to close #469 and #473

**NOTE: BUILT ON TOP OF #466

A) [X] Documents how to change a "model" field via JavaScript
B) [X] Fixes a problem where a `select` element is rendered without an `empty` option, and so the component data isn't aware of the pre-selected option.
C) [X] Automatically set the `value` of a `data-model` field - #473.

Cheers!

Commits
-------

af084ba doc'ing how to set values via JS, auto-set "value" of model elements, sync empty select fields
weaverryan added a commit that referenced this pull request Sep 27, 2022
…verryan)

This PR was merged into the 2.x branch.

Discussion
----------

[Live] Action and Model-based data-loading behavior

| Q             | A
| ------------- | ---
| Bug fix?      | yes/no
| New feature?  | yes
| Tickets       | Fix #462 and Feature E
| License       | MIT

NOTE: BUILT ON TOP OF #466.

Been wanting this for awhile :): only trigger loading behavior on an element for a specific action.

```
<span data-loading="action(saveForm)|show">Loading</span>
```

Or only when a specific model has been updated:

```
<span data-loading="model(email)|show">Loading</span>
```

TODO:

* [x] Let's also add "model" loading to this PR as well

Commits
-------

4e846d8 data-load only for specific actions or model updates
fullstackdeveloperwebapp added a commit to fullstackdeveloperwebapp/ux that referenced this pull request Aug 1, 2023
… sync bug & auto-setting data-model values (weaverryan)

This PR was merged into the 2.x branch.

Discussion
----------

[Waiting][Live] Doc'ing how to set values via Js, select sync bug & auto-setting data-model values

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| Tickets       | Fixes #469 Fixes #473
| License       | MIT

This does 3 unrelated things to close #469 and #473

**NOTE: BUILT ON TOP OF symfony/ux#466

A) [X] Documents how to change a "model" field via JavaScript
B) [X] Fixes a problem where a `select` element is rendered without an `empty` option, and so the component data isn't aware of the pre-selected option.
C) [X] Automatically set the `value` of a `data-model` field - #473.

Cheers!

Commits
-------

af084ba doc'ing how to set values via JS, auto-set "value" of model elements, sync empty select fields
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants