Fix mergeConfig dropping state when a config in the chain is async#1754
Open
durvesh1992 wants to merge 1 commit into
Open
Fix mergeConfig dropping state when a config in the chain is async#1754durvesh1992 wants to merge 1 commit into
durvesh1992 wants to merge 1 commit into
Conversation
When a config (function returning a Promise) appears mid-chain, mergeConfig handed off to mergeConfigAsync with two bugs: - It passed reversedConfigs.toReversed() as a single argument instead of spreading it into the rest parameter, so the remaining configs were wrapped in an extra array and merged as junk (e.g. an index key '0'). - It passed the unresolved promise as the base, discarding currentConfig (the base merged with every config to the left of the async one). Spread the remaining configs and fold currentConfig into the resolved async config so prior merges and trailing overrides are both preserved. Adds a regression test (async config function followed by an override) that fails before and passes after.
Contributor
|
@rozele has imported this pull request. If you are a Meta employee, you can view this in D110207654. |
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.
Summary
When
mergeConfig(base, ...configs)encounters a config that resolves to aPromise(e.g. an asyncmetro.config.js/ a config function returning a promise) and at least one more config follows it, it hands off tomergeConfigAsyncwith two defects:mergeConfigAsync(baseConfig, ...reversedConfigs)takes a rest parameter, but the call passedreversedConfigs.toReversed()as a single array argument. The remaining configs end up wrapped one level too deep, so they're merged as a bogus object (producing junk keys like"0") instead of being applied as configs.currentConfig(the base merged with every config to the left of the async one) was discarded — the unresolved promise was passed as the base, so all prior merges were lost.The fix spreads the remaining configs into the rest parameter and folds
currentConfiginto the resolved async config so both the accumulated state and the trailing overrides are preserved.Test plan
The existing
mergeConfigtests only cover sync configs, so this path was uncovered. Added a regression test (an async config function followed by a trailing override) asserting the base, the async config, and the trailing override all survive:result.server.portisundefined(base dropped); trailing override mangled.