Skip to content

Commit

Permalink
[11.x] Fixes exception rendering (#51587)
Browse files Browse the repository at this point in the history
* Cleans queries on job processed

* Avoids double rendering

* Removes temp variable
  • Loading branch information
nunomaduro authored May 28, 2024
1 parent d35c5d3 commit 42142ae
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 18 deletions.
6 changes: 6 additions & 0 deletions src/Illuminate/Foundation/Exceptions/Renderer/Listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Database\Events\QueryExecuted;
use Illuminate\Queue\Events\JobProcessed;
use Illuminate\Queue\Events\JobProcessing;
use Laravel\Octane\Events\RequestReceived;
use Laravel\Octane\Events\RequestTerminated;
use Laravel\Octane\Events\TaskReceived;
Expand All @@ -28,6 +30,10 @@ public function registerListeners(Dispatcher $events)
{
$events->listen(QueryExecuted::class, [$this, 'onQueryExecuted']);

$events->listen([JobProcessing::class, JobProcessed::class], function () {
$this->queries = [];
});

if (isset($_SERVER['LARAVEL_OCTANE'])) {
$events->listen([RequestReceived::class, TaskReceived::class, TickReceived::class, RequestTerminated::class], function () {
$this->queries = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@
hljs.initLineNumbersOnLoad()
window.addEventListener('load', function() {
document.querySelectorAll('.renderer').forEach(function(element, index) {
if (index > 0) {
element.remove();
}
});
document.querySelector('.default-highlightable-code').style.display = 'block';
document.querySelectorAll('.highlightable-code').forEach(function(element) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
<script>
const darkStyles = document.querySelector('style[data-theme="dark"]')?.textContent
const lightStyles = document.querySelector('style[data-theme="light"]')?.textContent
const removeStyles = () => {
document.querySelector('style[data-theme="dark"]')?.remove()
document.querySelector('style[data-theme="light"]')?.remove()
}
(function () {
const darkStyles = document.querySelector('style[data-theme="dark"]')?.textContent
const lightStyles = document.querySelector('style[data-theme="light"]')?.textContent
removeStyles()
const removeStyles = () => {
document.querySelector('style[data-theme="dark"]')?.remove()
document.querySelector('style[data-theme="light"]')?.remove()
}
setDarkClass = () => {
removeStyles()
const isDark = localStorage.theme === 'dark' || (!('theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches)
setDarkClass = () => {
removeStyles()
const isDark = localStorage.theme === 'dark' || (!('theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches)
isDark ? document.documentElement.classList.add('dark') : document.documentElement.classList.remove('dark')
isDark ? document.documentElement.classList.add('dark') : document.documentElement.classList.remove('dark')
if (isDark) {
document.head.insertAdjacentHTML('beforeend', `<style data-theme="dark">${darkStyles}</style>`)
} else {
document.head.insertAdjacentHTML('beforeend', `<style data-theme="light">${lightStyles}</style>`)
if (isDark) {
document.head.insertAdjacentHTML('beforeend', `<style data-theme="dark">${darkStyles}</style>`)
} else {
document.head.insertAdjacentHTML('beforeend', `<style data-theme="light">${lightStyles}</style>`)
}
}
}
setDarkClass()
setDarkClass()
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', setDarkClass)
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', setDarkClass)
})();
</script>
<div
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<x-laravel-exceptions-renderer::layout :$exception>
<div class="container mx-auto lg:px-8">
<div class="renderer container mx-auto lg:px-8">
<x-laravel-exceptions-renderer::navigation :$exception />

<main class="px-6 pb-12 pt-6">
Expand Down

0 comments on commit 42142ae

Please sign in to comment.