fix(core): Allow to return a new hook context in basic hooks#2462
fix(core): Allow to return a new hook context in basic hooks#2462
Conversation
|
Wait, but it wasn't an unexpected regression, it was a deliberate choice for depreciation in next major version advocated by me in #1443. This current fix, while small and easy creates a different behavior from v4. Here you just
And migration is easy, they could have done the same that was done here - instead of Anyway, you can ignore this message, just had to write since it was me who proposed depreciation. |
|
Ah yes, sorry I remember now. The problem with this approach was that I heard from a couple of beta testers now that they are ensuring immutability in their projects and did something like: context => {
return {
...context,
params
}
}The problem with the new implementation was that it just did nothing and you had no idea why. You may be right in that it makes more sense to throw an error if a different context than the original one is returned. |
Legacy hook return type should have been updated to reflect that returning is not an option anymore. Then they could see (at least those who use typescript) an error at writing time instead of compile/runtime one.
Good intention, but stems from miscommunication (docs and types). Originally returning new context was added (as you said) with an idea of a pure hook (receive input, return output without side effects), but it was never actually implemented like that in the end. So no profits, only costs for that mirage... Another smallish thing is that migration from void hooks to async hooks are easier than from returning ones. So if you plan to force migration to new hooks in the distant future (one or two versions down the line), they would still need to update. |
This fixes a regression in backwards compatibility that is difficult to debug.
Closes #2451