fix: guard against undefined module in ModuleCollection.get() (fix #2164) - #2274
Open
JSap0914 wants to merge 1 commit into
Open
fix: guard against undefined module in ModuleCollection.get() (fix #2164)#2274JSap0914 wants to merge 1 commit into
JSap0914 wants to merge 1 commit into
Conversation
…ejs#2164) When isRegistered() is called with a path whose intermediate segments do not exist (e.g. ['a', 'b', 'c'] where 'a' is not registered), the reduce inside get() called .getChild() on undefined, throwing a TypeError. The fix short-circuits the reduce by returning undefined when the accumulated module is falsy, matching the existing null-guard already present in isRegistered() itself. Added a regression test for the 3-level non-existent path case.
✅ Deploy Preview for vuex-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
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.
Problem
store.hasModule(path)throws aTypeErrorwhen called with a path that is 3 or more levels deep and no intermediate module exists.Reproduction:
The crash originates in
ModuleCollection.get():When the first segment is not registered,
getChildreturnsundefined. The next iteration then callsundefined.getChild(...), which throws.isRegistered()already has aif (parent)guard after callingget(), but that guard is never reached becauseget()throws first.This was partially addressed in #1851 for 2-level paths, but the
get()method itself was not fixed, so paths of 3+ non-existent segments still crash.Fix
Short-circuit the
reducewhen the accumulated module is falsy:This is a one-character change that makes
get()returnundefinedinstead of throwing, allowing the existing guard inisRegistered()to do its job.Testing
Added a regression test for the 3-level non-existent path case. All 102 existing unit tests continue to pass.