-
Notifications
You must be signed in to change notification settings - Fork 392
fix(core): preserve RN initial page params #2560
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
mackwang112
wants to merge
18
commits into
master
Choose a base branch
from
fix-page-params
base: master
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.
Open
Changes from 10 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
6a6ab8e
fix(core): preserve RN initial page params
mackwang112 02ef76c
Merge branch 'master' into fix-page-params
hiyuki ea64b6d
fix(core): use initial state for RN launch params
Blackgan3 6058f64
Merge branch 'master' into fix-page-params
Blackgan3 dd1b690
test(core): define perf globals for Jest
Blackgan3 4f14d37
fix(core): handle invalid RN initial routes
Blackgan3 b848cb9
Merge branch 'master' into fix-page-params
Blackgan3 510bd4d
fix(core): clarify RN initial route fallback message
Blackgan3 01397ab
refactor(core): validate RN initial route during app props parsing
Blackgan3 34ebc05
test(core): simplify RN initial params tests
Blackgan3 95d2969
fix(core): validate only explicit RN initial routes
Blackgan3 bd8c1e8
fix(core): discard invalid RN initial route configs
Blackgan3 bc087d6
docs: revert initial route documentation sync
Blackgan3 68771f5
style(core): expand initial route assignment conditionals
Blackgan3 1306613
refactor(core): handle valid initial routes first
Blackgan3 3a815d7
refactor(core): restore invalid initial route guard first
Blackgan3 ce6c4b2
Merge branch 'master' into fix-page-params
hiyuki b6ec3f2
Merge branch 'master' into fix-page-params
hiyuki 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| global.__mpx_mode__ = 'ios' | ||
|
|
||
| const createApp = require('../../src/platform/createApp.ios').default | ||
| const transferOptions = require('../../src/core/transferOptions') | ||
| const Mpx = require('../../src/index') | ||
| const { error } = require('@mpxjs/utils') | ||
|
|
||
| jest.mock('../../src/core/transferOptions', () => jest.fn()) | ||
|
|
||
| jest.mock('@mpxjs/utils', () => Object.assign({}, jest.requireActual('@mpxjs/utils'), { | ||
| error: jest.fn() | ||
| })) | ||
|
|
||
| jest.mock('../../src/index', () => ({ config: { rnConfig: {} }, prototype: {} })) | ||
|
|
||
| jest.mock('../../src/observer/reactive', () => ({ | ||
| reactive: (value) => value | ||
| })) | ||
|
|
||
| jest.mock('../../src/observer/watch', () => ({ | ||
| watch: jest.fn() | ||
| })) | ||
|
|
||
| jest.mock('react', () => ({ | ||
| createElement: (type, props, ...children) => ({ | ||
| type, | ||
| props: Object.assign({}, props, { children }) | ||
| }), | ||
| memo: (component) => component, | ||
| useRef: (value) => ({ current: value }), | ||
| useEffect: jest.fn() | ||
| }), { virtual: true }) | ||
|
|
||
| jest.mock('react-native', () => ({}), { virtual: true }) | ||
|
|
||
| jest.mock('../../src/platform/export/inject', () => ({ | ||
| initAppProvides: jest.fn() | ||
| })) | ||
|
|
||
| jest.mock('../../src/platform/env/navigationHelper', () => ({ | ||
| NavigationContainer: 'NavigationContainer', | ||
| createNativeStackNavigator: () => ({ | ||
| Navigator: 'StackNavigator', | ||
| Screen: 'StackScreen' | ||
| }), | ||
| SafeAreaProvider: 'SafeAreaProvider', | ||
| GestureHandlerRootView: 'GestureHandlerRootView' | ||
| }), { virtual: true }) | ||
|
|
||
| jest.mock('@mpxjs/webpack-plugin/lib/runtime/components/react/dist/mpx-nav', () => 'MpxNav', { virtual: true }) | ||
|
|
||
| describe('RN createApp initial params', () => { | ||
| const onLaunch = jest.fn() | ||
|
|
||
| beforeEach(() => { | ||
| jest.clearAllMocks() | ||
| global.__mpxOptionsMap = {} | ||
| global.__mpxPageConfig = {} | ||
| global.__mpxPageConfigsMap = {} | ||
| Mpx.config.rnConfig = {} | ||
| transferOptions.mockReturnValue({ | ||
| rawOptions: { onLaunch }, | ||
| currentInject: { | ||
| moduleId: 'app', | ||
| firstPage: 'pages/home', | ||
| pagesMap: { | ||
| 'pages/home': () => null, | ||
| 'pages/index': () => null | ||
| } | ||
| } | ||
| }) | ||
| }) | ||
|
|
||
| function renderApp (initialRouteName, initialParams) { | ||
| Mpx.config.rnConfig.parseAppProps = () => ({ initialRouteName, initialParams }) | ||
| createApp({}) | ||
| return global.__mpxOptionsMap.app({}).props.children[0] | ||
| } | ||
|
|
||
| it('uses initialState for a non-first Screen instead of Navigator and Screen defaults', () => { | ||
| const initialParams = { a: 1 } | ||
| const navigationContainer = renderApp('pages/index', initialParams) | ||
| const stackNavigator = navigationContainer.props.children[0] | ||
| const indexScreen = stackNavigator.props.children[1] | ||
|
|
||
| expect(navigationContainer.props.initialState).toEqual({ | ||
| routes: [{ | ||
| name: 'pages/index', | ||
| params: initialParams | ||
| }] | ||
| }) | ||
| expect(stackNavigator.props).not.toHaveProperty('initialRouteName') | ||
| expect(indexScreen.props).not.toHaveProperty('initialParams') | ||
|
|
||
| global.__mpxAppOnLaunch({ | ||
| getState: () => Object.assign({ index: 0 }, navigationContainer.props.initialState) | ||
| }) | ||
| expect(onLaunch).toHaveBeenCalledWith(expect.objectContaining({ | ||
| path: 'pages/index', | ||
| query: initialParams, | ||
| isLaunch: true | ||
| })) | ||
| }) | ||
|
|
||
| it('reports and falls back when the initial route is not registered', () => { | ||
| const navigationContainer = renderApp('pages/missing', { fromMissing: true }) | ||
|
|
||
| expect(error).toHaveBeenCalledTimes(1) | ||
| expect(error).toHaveBeenCalledWith('The initial page [pages/missing] is not registered in the application. Mpx will fall back to the first page [pages/home].') | ||
| expect(navigationContainer.props.initialState).toEqual({ | ||
| routes: [{ | ||
| name: 'pages/home', | ||
| params: {} | ||
| }] | ||
| }) | ||
| }) | ||
| }) |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.