Repository navigation
Fix running= with an ALL wildcard crashing when no components match #3957
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
Mohit-Ak
wants to merge
3
commits into
plotly:dev
Choose a base branch
from
Mohit-Ak:fix/running-all-empty-page
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+185
−3
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| import {expect} from 'chai'; | ||
| import {beforeEach, describe, it} from 'mocha'; | ||
| import {getAllPMCIds, replacePMC} from '../src/actions/patternMatching'; | ||
|
|
||
| // Minimal stand-in for the pieces of the redux state that the pattern | ||
| // matching helpers read. | ||
| function makeState(objs) { | ||
| return {paths: {strs: {}, objs: objs || {}}}; | ||
| } | ||
|
|
||
| // A wildcard entry as produced by crawling the layout: `values` is the list | ||
| // of id values ordered by the (sorted) id keys. | ||
| function entries(keyStr, valueLists) { | ||
| return { | ||
| [keyStr]: valueLists.map((values, i) => ({ | ||
| values, | ||
| path: ['props', 'children', i] | ||
| })) | ||
| }; | ||
| } | ||
|
|
||
| const cb = {parsedChangedPropsIds: [{id: 'home1', type: 'loading'}]}; | ||
|
|
||
| describe('getAllPMCIds', () => { | ||
| it('returns the matching ids when the wildcard key is registered', () => { | ||
| const state = makeState( | ||
| entries('id,type', [ | ||
| ['home1', 'loading'], | ||
| ['home2', 'loading'] | ||
| ]) | ||
| ); | ||
| const result = getAllPMCIds( | ||
| {id: ['ALL'], type: 'loading'}, | ||
| state, | ||
| 'id' | ||
| ); | ||
| expect(result).to.deep.equal([ | ||
| {id: 'home1', type: 'loading'}, | ||
| {id: 'home2', type: 'loading'} | ||
| ]); | ||
| }); | ||
|
|
||
| it('returns an empty list when no component uses that id shape', () => { | ||
| // This is the state on a page that renders none of the wildcard | ||
| // components: `paths.objs['id,type']` was never populated. | ||
| const result = getAllPMCIds( | ||
| {id: ['ALL'], type: 'loading'}, | ||
| makeState({}), | ||
| 'id' | ||
| ); | ||
| expect(result).to.deep.equal([]); | ||
| }); | ||
| }); | ||
|
|
||
| describe('replacePMC', () => { | ||
| let getState; | ||
|
|
||
| beforeEach(() => { | ||
| getState = () => | ||
| makeState( | ||
| entries('id,type', [ | ||
| ['home1', 'loading'], | ||
| ['home2', 'loading'] | ||
| ]) | ||
| ); | ||
| }); | ||
|
|
||
| it('expands ALL to every matching component', () => { | ||
| const result = replacePMC( | ||
| {id: ['ALL'], type: 'loading'}, | ||
| cb, | ||
| 0, | ||
| getState | ||
| ); | ||
| expect(result).to.deep.equal([ | ||
| {id: 'home1', type: 'loading'}, | ||
| {id: 'home2', type: 'loading'} | ||
| ]); | ||
| }); | ||
|
|
||
| it('resolves MATCH against the triggering id', () => { | ||
| const result = replacePMC( | ||
| {id: ['MATCH'], type: 'loading'}, | ||
| cb, | ||
| 0, | ||
| getState | ||
| ); | ||
| expect(result).to.deep.equal([{id: 'home1', type: 'loading'}]); | ||
| }); | ||
|
|
||
| it('leaves a fully concrete id untouched', () => { | ||
| const result = replacePMC( | ||
| {id: 'home1', type: 'loading'}, | ||
| cb, | ||
| 0, | ||
| getState | ||
| ); | ||
| expect(result).to.deep.equal([{id: 'home1', type: 'loading'}]); | ||
| }); | ||
|
|
||
| it('yields no ids when ALL matches nothing on the current page', () => { | ||
| // Regression test for #3297: navigating to a page that has none of | ||
| // the wildcard components used to throw | ||
| // `state.paths.objs[idKey] is undefined`, and later returned a | ||
| // partial id missing the wildcard key. | ||
| const empty = () => makeState({}); | ||
| const result = replacePMC({id: ['ALL'], type: 'loading'}, cb, 0, empty); | ||
| expect(result).to.deep.equal([]); | ||
| }); | ||
|
|
||
| it('yields no ids when ALLSMALLER matches nothing on the current page', () => { | ||
| const empty = () => makeState({}); | ||
| const result = replacePMC( | ||
| {id: ['ALLSMALLER'], type: 'loading'}, | ||
| cb, | ||
| 0, | ||
| empty | ||
| ); | ||
| expect(result).to.deep.equal([]); | ||
| }); | ||
| }); |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This early return is the half of the fix that keeps the unresolved pattern (
{type: 'loading'}with noid) out ofupdateComponent, and it has no test. The unit tests stop atreplacePMCreturning[]and never reach this branch. Add an integration test modeled ontest_cbwc008_running_matchthat reproduces #3297 directly: multi-page app, navigate to a page with none of theALLcomponents, click, then assert the console is clean and the callback output updated. That exercises this line and proves the actual crash is gone.