Skip to content

fix!: guarantee immutable config updates for plugins #12373

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

AlessioGr
Copy link
Member

@AlessioGr AlessioGr commented May 11, 2025

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

  • All config mutations now go through Immer
    • Guarantees immutability and eliminates accidental cross-plugin side effects.

⚠️ BREAKING CHANGE

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

@AlessioGr AlessioGr added the 4.0 label May 14, 2025
@AlessioGr AlessioGr changed the title fix: guarantee immutable config updates for plugins fix!: guarantee immutable config updates for plugins May 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant