Animation Disabler is installed as a rack middleware - it will be
instantiated once and the call method will be called by multiple
requests.
The code was using instance variables on the middleware for information
about individual requests. When multiple requests were made at the same
time, the subsequent request would replace the status/headers/body of
the original request, causing the original request to return the
response of the subsequent request.
The W3C Validator was reporting an error:
> Element style not allowed as child of element body in this context.
>
> Contexts in which element style may be used:
> Where metadata content is expected.
> In a noscript element that is a child of a head element.
> Content model for element body:
> Flow content.
It looks like there can't be any <style> tags inside the <body> element
[1].
The <script> part of the markup template remains at the end of the
<body> element because it only makes sense if jQuery has already been
defined, and jQuery could be defined anywhere inside the <head> or
<body> elements.
[1] https://html.spec.whatwg.org/multipage/semantics.html#the-style-element
When writing a new Rails system test I ran into an issue where the
browser would hang and not close, eventually failing the test due to
pending requests. There were no clear pending requests and the requests
mentioned were AJAX calls that should have been made several pages ago.
I believe the cause is an AJAX call being cancelled almost immediately
after it was initiated, but I'm not 100% positive.
Code wise, it looks like the value of `env['REQUEST_URI']` that
increments the counter is different from the `env['REQUEST_URI']` that's
decremented in the `ensure` block.
This resolves the issue by storing the `env['REQUEST_URI']` value in a
variable so it will be consistent between counter calls.
* Backfill tests on pending requests behavior
* Implement parameterized wait time for wait_for_oending_requests
At some point, this might be worth being a top-level configuration.
* Re-implement counter mutex with a list of pending request envs
Set up for exposing more information to developers about pending requests.
* Expose pending requests in error message
This provides a bit more information to other developers about the state of their tests. Whether we include further information would require more feedback from other developers and how the community use the error message for debugging.
* Add safe fallback value to avoid passing `nil`
* Use a memory barrier on read operations for array
* Only store REQUEST_URI instead of env
* Revert back to fixed wait_time (60)
Keeping initial PR tidy and focused.
* Remove redundant attr reader
We already defined a getter for the value to ensure proper concurrent accessing.
* Ruby linter: single-line body for modifier if usage
* Ruby linter: single quotes
If it receives a falsey (false or nil) it won't do anything.
If it receives true, it will disable animations on the '*' css selector
If it receives a string, it will use that string as the css selector
It will still always disable css for jQuery if it's around.