-
Notifications
You must be signed in to change notification settings - Fork 415
[Bug?]: V2 middleware functions do not execute in order #2131
Copy link
Copy link
Open
Labels
Description
Duplicates
- I have searched the existing issues
Latest version
- I have tested the latest version
Current behavior 😯
onRequest functions execute in order
onBeforeResponse functions execute in inconsistent (backwards?) order
Expected behavior 🤔
onBeforeResponse functions execute in order
Steps to reproduce 🕹
Steps:
- create new V2 project
- create middleware file with this code
import { createMiddleware } from '@solidjs/start/middleware'
const one = async () => {
console.log('begin one')
await new Promise(resolve => setTimeout(resolve, Math.random() * 1000))
console.log('end one')
}
const two = async () => {
console.log('begin two')
await new Promise(resolve => setTimeout(resolve, Math.random() * 1000))
console.log('end two')
}
const three = async () => {
console.log('begin three')
await new Promise(resolve => setTimeout(resolve, Math.random() * 1000))
console.log('end three')
}
const four = async () => {
console.log('begin four')
await new Promise(resolve => setTimeout(resolve, Math.random() * 1000))
console.log('end four')
}
const five = async () => {
console.log('begin five')
await new Promise(resolve => setTimeout(resolve, Math.random() * 1000))
console.log('end five')
}
const six = async () => {
console.log('begin six')
await new Promise(resolve => setTimeout(resolve, Math.random() * 1000))
console.log('end six')
}
const seven = async () => {
console.log('begin seven')
await new Promise(resolve => setTimeout(resolve, Math.random() * 1000))
console.log('end seven')
}
const eight = async () => {
console.log('begin eight')
await new Promise(resolve => setTimeout(resolve, Math.random() * 1000))
console.log('end eight')
}
const nine = async () => {
console.log('begin nine')
await new Promise(resolve => setTimeout(resolve, Math.random() * 1000))
console.log('end nine')
}
const ten = async () => {
console.log('begin ten')
await new Promise(resolve => setTimeout(resolve, Math.random() * 1000))
console.log('end ten')
}
export default createMiddleware({
onRequest: [
one,
two,
three,
four,
],
onBeforeResponse: [
five,
six,
seven,
eight,
nine,
ten,
]
})- observe how it is different than V1
Context 🔦
trying to migrate to V2 and realized some middleware functions were breaking because values they expected were supposed to be populated by previous functions, but those functions were not called yet because it is happening out of order
Your environment 🌎
Reactions are currently unavailable