#beforeLoad never called when using with Webpack's FederationPlugin

16 messages · Page 1 of 1 (latest)

twilit flower
#

I'm still trying to figure out issue, but it's haunting me for a while. I have a special routing library built on top of the Tanstack Router, and when I use the library directly it works pretty well – I have specific contexts defined in the beforeLoad, which are becoming part of the Route Context.
However, when I start it in an environment with Webpack's FederationPlugin, the context is never collected as the beforeLoad is never ever called. Other issues aside, I cannot figure out the conditions where that could happen.
I see that, hypothetically, there could be some silenced exception here: https://github.com/TanStack/router/blob/9d98af6659004e226970e6e49f7a756353e8f055/packages/react-router/src/router.ts#L1365, but I've tried to catch that – no luck.

GitHub

🤖 Fully typesafe Router for React (and friends) w/ built-in caching, 1st class search-param APIs, client-side cache integration and isomorphic rendering. - TanStack/router

#

I am not certain but how likely are the chances that async generators in webpack are bugged?

twilit flower
#

Upd: the __generator is added by the typescript, not webpack

echo bridge
#

Weird. Is this happening on the server?

twilit flower
#

That is one of the craziest bugs I've had. It's caused by "ts-loader": "^9.4.1", with target es5

#

I've changed tartget to es2020 and the context is finnaly there and the beforeLoad works

echo bridge
#

WAT

#

That’s insane

twilit flower
#

I can't believe my eyes to be honest

#

Not ts-loader, looks like it's a feature of TypeScript transpiller. I can't wrap my head around what is really happening there, but on es5, with __generator - I don't have any context, the loop is skipped, on es2020 - I do.

twilit flower
#

I'm having a hard time narrowing down the problem really, but overall:
The module/library on top of Tanstack Router is built fine, it does not turn original Tanstack code into es5 js.
When I import it, however, in a webpack project with typescript es5 target, it's somehow polyfilled, and polyfilled by the typescript it seems like because changing target in webpack doesn't change anything, but changing target in tsconfig.json does. Why and how typescript tries to polyfill JS code is beyond me, but this seems like exactly the issue here, that ts does something that it should not do. When these generators are added, the Tanstack Router match loop is entierly skipped, causing beforeLoad to never trigger.

echo bridge
#

That's weird

#

I'm not even sure where to file a bug

twilit flower
#

Looking more into it, I think it's my fault because I've somehow got ts-loader running over JS files (which it did for a while surprisingly well!), and exclusion of /node_modules/ didn't stop it for some reason. It's just a very weird and unexpected result of misconfiguration. Okay, thank you very much, closing this topic!