Repository navigation
fix(config): merge preset and user hooks instead of overriding - #4809
Merged
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configuration
📒 Files selected for processing: 6
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Same-named hooks from base preset, preset, config, $env and overrides layers now all run in order (lowest priority first) using hookable's mergeHooks.
pi0x
force-pushed
the
fix/preset-hooks-merge
branch
from
October 17, 2026 12:23
e2b8146 to
9e48d99
Compare
commit: |
pi0
approved these changes
Oct 17, 2026
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Resolves #1382
Config layers were merged with plain
defu, so when two layers defined a hook with the same name (for example a preset'scompiledhook andhooks.compiledin the user config), the higher priority one replaced the other and the preset hook never ran.This PR merges the top-level
hookskey with hookable'smergeHooksinstead:merger(and the same handling in the existingenvMerger). Every layer's hook now runs, lowest priority first: base preset, preset, config file,$envoverrides, then programmatic overrides. So user hooks run after the preset's and can work with what the preset produced.setupNitroContextused plaindefuacrossnitro({...})options, plugin config and the Vite config'snitrokey, so the same problem happened there. It now uses the same merger. Order: preset,nitro.config, Vite confignitrokey, thennitro()options.src/config/_merge.ts. Nested and flat hook names (rollup: { before }and"rollup:before") are merged together too.I checked every built-in preset that uses
extends. None of them currently redefines a hook that its base preset also defines, so no preset needed changes and nothing runs twice.Behavior change: before, defining a hook with the same name (even an empty one) silently disabled the preset's hook. That is no longer possible (noted in the config docs), and third-party presets that relied on replacing their base preset's hook will now run both. Also, when several hooks share a name they are combined into one serial async function, so
removeHook(name, originalFn)won't find the original function in that case.Tests:
test/unit/config-hooks.test.ts: preset + config + overrides, nested and flat names,$productionwith base hooks.test/vite/plugin-hooks.test.ts: hooks in bothnitro()options and the Vite config'snitrokey.Both fail on
mainand pass with this change.pnpm typecheck,pnpm test:rollupand thetest/vitesuite pass.🤖 Generated with AI assistant