#Global Middleware not working after devinxi?

62 messages · Page 1 of 1 (latest)

amber widget
#

I'm finally getting around to updating my production app with the devinxi updates (1.120.3 --> 1.123.2). Everything seems to be working so far except my global middleware.

I've searched and found two GH Issues about global middleware not working (opened in Feb/Mar but have recent comments - e.g., https://github.com/TanStack/router/issues/3869) and at least one Discord post mentioning that global middleware isn't working.

I haven't seen anything concrete though about this being a known/accepted issue across the board. Maybe I just missed an Issue or something. Is it working for some people? Or is it not working at all post-1.121?

If this is a known issue with 1.121+, please let me know if there's anything I can do to help!

deft robin
#

import the global middleware file somewhere

i took the habit of importing it everywhere i create a server function

solemn wind
#

yes this is a known issue, we still need to implement global middlware registration now that devinxi has happened

amber widget
#

Okay, thanks for the confirmation!

#

I tried adding import "@/global-middleware"; in __root.tsx just to see what happened. My logging middleware did start running but I was getting many duplicate executions (10-20x).

I can hold out for the fix. I'd rather not manually add logging middleware to a few dozen individual server functions just to remove it later.

icy rose
#

try importing it from router.tsx instead

amber widget
#

Thanks. I tried that but I still get duplicates. It stops at the 11th due to MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 data listeners added to [IncomingMessage]. MaxListeners is 10. Use emitter.setMaxListeners() to increase limit.

No rush on my end. I've been running fine in production on 1.120.3 for a month so I don't mind holding out longer for the official fix.

azure bay
#

I ran into the same issue. @solemn wind You are probably busy, so no rush or pressure. But do you have any estimation of when this might be fixed? It would really help! 😄

solemn wind
#

it will take some more time I am sorry. but it is not forgotten

timber walrus
#

This helped a lot.
I had to import it into the server fxn file.

#

Ready to also help with documentation if this is ready ☺️

radiant crown
solemn wind
#

not yet.

radiant crown
# solemn wind not yet.

Is there a workaround? And is it possible to use AsyncLocalStorage from Node with it? It works with loeaders?

solemn wind
#

start uses async local storage already internally, so yes it works

#

what do you want to do with ALS here?

radiant crown
#

getLocale() does not work with the loader. It would be nice to see an example of TS Start with ASL

solemn wind
#

where is getLocale() defined?

radiant crown
#

It is compiled from paraglide

solemn wind
#

and what is it? what does it do?

radiant crown
#

I will commit the generated files

solemn wind
#

why wouldnt an ordinary function work in a loader?

#

does it never "work" or just not on the client or server?

radiant crown
#

Actually it works on the first visit, but when changing locale it does not work properly

solemn wind
#

so it does not work on the client then?

#

i mean after a client navigation?

radiant crown
#

When I switch the locale in the client, the loader gets the old locale

#

I will come up with the complete example

solemn wind
#

ALS wont help you on the client

#

as this is a server only thing

radiant crown
#

But subquent navigations on the loader always come from server right?

solemn wind
#

the loader runs on the client

#

after the initial SSR response

radiant crown
#

If I have a server only function that invokes my db with envs, it will run on the client after the inital SSR?

solemn wind
#

no. a server function always runs on the server

#

but the loader that invokes the server function runs on the client

radiant crown
#

I am not using server functions

#

As I am concerned, the loader runs only on the server when ssr: true

#

Full example with the paraglide files:

solemn wind
radiant crown
#

will test this, but getLocale works on the client and the server

radiant crown
#

The locale from client works, but the locale from loades does not

solemn wind
#

it lags behind?

radiant crown
solemn wind
#

how are path param and lingqui connected?

#

i dont understand what this should do here

#

can you explain what you are trying to do please?

radiant crown
rotund pewter
#

Same issue here, as a workaround, i put the registerGlobalMiddleware calls into __root.tsx, which seems to work

radiant crown
#

But I think the loader is loading before the midleware and the server entry point

#

If I do this: beforeLoad: ({ params }) => {
overwriteGetLocale(() => params.locale);
},

It works. But overwriting get locale in the server entry point and midleware does not work because the loader invokes before it

radiant crown