fix!: guarantee immutable config updates for plugins #12373
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Why
It's easy to introduce hard-to-debug bugs when parts of a config object are shared across multiple locations and plugins mutate these shared references directly without creating shallow copies.. By switching to Immer, every update goes through structural sharing, so each plugin works with an immutable snapshot instead of a live object.
What’s changed
Plugins must not capture the config argument in long-lived closures (e.g. route or endpoint handlers).
Once plugins have run, Immer revokes the draft proxy; any later access throws a
TypeError: Cannot perform 'get' on a proxy that has been revoked
See the Immer discussion: immerjs/immer#430.
Recommended migration path
Access configuration at run time via
req.payload.config
instead of the plugin-time config argument. Alternatively, we could pass the non-proxied config as second argument to the plugin function