From 2536368e774a9028f86180b00f22dc2c7bb47323 Mon Sep 17 00:00:00 2001 From: Julien Nahum Date: Fri, 27 Jan 2023 18:55:02 +0100 Subject: [PATCH] =?UTF-8?q?Fix=20JS=20middlewares=20=E2=9A=92=EF=B8=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 1 + composer.lock | 64 ++++++++++++++++++++++++++++++++++-- phpunit.xml | 1 - resources/js/router/index.js | 24 +++++++++----- 4 files changed, 78 insertions(+), 12 deletions(-) diff --git a/composer.json b/composer.json index 9d50e70..0c0bff2 100644 --- a/composer.json +++ b/composer.json @@ -48,6 +48,7 @@ "barryvdh/laravel-ide-helper": "^2.12", "fakerphp/faker": "^1.9.1", "laravel/dusk": "^6.8", + "laravel/sail": "^1.18", "mockery/mockery": "^1.4.2", "nunomaduro/collision": "^6.1", "pestphp/pest": "^1.15", diff --git a/composer.lock b/composer.lock index 69b9d30..baaf06e 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f7f1a45b1eda3403d140b878030defd7", + "content-hash": "2e93597a584b3252f740cd2bd6e0a0da", "packages": [ { "name": "asm89/stack-cors", @@ -11462,6 +11462,66 @@ }, "time": "2022-09-29T09:37:07+00:00" }, + { + "name": "laravel/sail", + "version": "v1.18.1", + "source": { + "type": "git", + "url": "https://github.com/laravel/sail.git", + "reference": "a64f78a4ab86c04a4c5de39bea20a8d36ad48a22" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/laravel/sail/zipball/a64f78a4ab86c04a4c5de39bea20a8d36ad48a22", + "reference": "a64f78a4ab86c04a4c5de39bea20a8d36ad48a22", + "shasum": "" + }, + "require": { + "illuminate/console": "^8.0|^9.0|^10.0", + "illuminate/contracts": "^8.0|^9.0|^10.0", + "illuminate/support": "^8.0|^9.0|^10.0", + "php": "^7.3|^8.0" + }, + "bin": [ + "bin/sail" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + }, + "laravel": { + "providers": [ + "Laravel\\Sail\\SailServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "Laravel\\Sail\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylor@laravel.com" + } + ], + "description": "Docker files for running a basic Laravel application.", + "keywords": [ + "docker", + "laravel" + ], + "support": { + "issues": "https://github.com/laravel/sail/issues", + "source": "https://github.com/laravel/sail" + }, + "time": "2023-01-11T14:35:04+00:00" + }, { "name": "mockery/mockery", "version": "1.5.1", @@ -14746,5 +14806,5 @@ "ext-pcntl": "8.0", "ext-posix": "8.0" }, - "plugin-api-version": "2.1.0" + "plugin-api-version": "2.3.0" } diff --git a/phpunit.xml b/phpunit.xml index 4ca3838..b5bbbec 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -25,7 +25,6 @@ - diff --git a/resources/js/router/index.js b/resources/js/router/index.js index 9953c0e..4f8c434 100644 --- a/resources/js/router/index.js +++ b/resources/js/router/index.js @@ -90,8 +90,6 @@ async function beforeEach (to, from, next) { router.app.setLayout(components[0].layout) } else if (components[0].default && components[0].default.layout) { router.app.setLayout(components[0].default.layout) - } else { - router.app.setLayout('') } } @@ -133,7 +131,10 @@ function callMiddleware (middleware, to, from, next) { return next(...args) } - const { middleware, params } = parseMiddleware(stack.pop()) + const { + middleware, + params + } = parseMiddleware(stack.pop()) if (typeof middleware === 'function') { middleware(to, from, _next, params) @@ -183,7 +184,6 @@ function getMiddleware (components) { const middleware = [...globalMiddleware] components.forEach(component => { - let compMiddleware if (component.middleware) { compMiddleware = component.middleware @@ -191,10 +191,12 @@ function getMiddleware (components) { compMiddleware = component.default.middleware } - if (Array.isArray(compMiddleware)) { - middleware.push(...compMiddleware) - } else { - middleware.push(compMiddleware) + if (compMiddleware) { + if (Array.isArray(compMiddleware)) { + middleware.push(...compMiddleware) + } else { + middleware.push(compMiddleware) + } } }) @@ -237,7 +239,11 @@ function scrollBehavior (to, from, savedPosition) { * @param {Object} requireContext * @return {Object} */ -function resolveMiddleware(requireContext) { +/** + * @param {Object} requireContext + * @return {Object} + */ +function resolveMiddleware (requireContext) { const middlewares = {} Object.keys(requireContext) .map(file =>