This repository has been archived by the owner on Mar 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
chore(docs): make HMR working properly #1370
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6cda6b4
chore(docs): make HMR working properly
layershifter cba38b0
Merge branch 'master' of https://github.com/stardust-ui/react into ch…
layershifter 2256c66
wip
layershifter 1ff9b95
Merge branch 'master' of https://github.com/stardust-ui/react into ch…
layershifter dfb6ec2
wip
layershifter 40b3b47
wip
layershifter 08ae0ad
wip
layershifter 5cabad4
fix typo
layershifter ef109b5
fix TS error
layershifter 91be85f
Merge branch 'master' into chore/enable-hmr
layershifter 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 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 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 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 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 |
---|---|---|
|
@@ -3,46 +3,12 @@ import * as ReactDOM from 'react-dom' | |
import { AppContainer } from 'react-hot-loader' | ||
import App from './app' | ||
|
||
// ---------------------------------------- | ||
// Rendering | ||
// ---------------------------------------- | ||
|
||
const mountNode = document.createElement('div') | ||
document.body.appendChild(mountNode) | ||
|
||
const render = NewApp => | ||
ReactDOM.render( | ||
<AppContainer> | ||
<NewApp /> | ||
</AppContainer>, | ||
mountNode, | ||
) | ||
|
||
// ---------------------------------------- | ||
// HMR | ||
// ---------------------------------------- | ||
|
||
if (__DEV__) { | ||
// When the application source code changes, re-render the whole thing. | ||
if (module.hot) { | ||
module.hot.accept('./app', () => { | ||
// restore scroll | ||
const { scrollLeft, scrollTop } = document.scrollingElement! | ||
ReactDOM.unmountComponentAtNode(mountNode) | ||
|
||
try { | ||
render(require('./app').default) | ||
document.scrollingElement!.scrollTop = scrollTop | ||
document.scrollingElement!.scrollLeft = scrollLeft | ||
} catch (e) { | ||
console.error(e) | ||
} | ||
}) | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This stuff will be done by |
||
|
||
// ---------------------------------------- | ||
// Start the app | ||
// ---------------------------------------- | ||
|
||
render(App) | ||
ReactDOM.render( | ||
<AppContainer> | ||
<App /> | ||
</AppContainer>, | ||
mountNode, | ||
) |
This file contains 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 |
---|---|---|
|
@@ -21,6 +21,18 @@ import AccessibilityBehaviors from './views/AccessibilityBehaviors' | |
import FocusZone from './views/FocusZone' | ||
import FocusTrapZone from './views/FocusTrapZone' | ||
import AutoFocusZone from './views/AutoFocusZone' | ||
import ChatPanePrototype from './prototypes/chatPane' | ||
import ChatMessagesPrototype from './prototypes/chatMessages' | ||
import AsyncShorthandPrototype from './prototypes/AsyncShorthand' | ||
import EmployeeCardPrototype from './prototypes/employeeCard' | ||
import MeetingOptionsPrototype from './prototypes/meetingOptions' | ||
import SearchPagePrototype from './prototypes/SearchPage' | ||
import MentionsPrototype from './prototypes/mentions' | ||
import DropdownsPrototype from './prototypes/dropdowns' | ||
import PopupsPrototype from './prototypes/popups' | ||
import IconViewerPrototype from './prototypes/IconViewer' | ||
import MenuButtonPrototype from './prototypes/MenuButton' | ||
import AlertsPrototype from './prototypes/alerts' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
const Router = () => ( | ||
<BrowserRouter basename={__BASENAME__}> | ||
|
@@ -35,74 +47,74 @@ const Router = () => ( | |
exact | ||
key="/prototype-chat-pane" | ||
path="/prototype-chat-pane" | ||
component={require('./prototypes/chatPane/index').default} | ||
component={ChatPanePrototype} | ||
/>, | ||
<DocsLayout | ||
exact | ||
key="/prototype-chat-messages" | ||
path="/prototype-chat-messages" | ||
component={require('./prototypes/chatMessages/index').default} | ||
component={ChatMessagesPrototype} | ||
/>, | ||
, | ||
<DocsLayout | ||
exact | ||
key="/prototype-async-shorthand" | ||
path="/prototype-async-shorthand" | ||
component={require('./prototypes/AsyncShorthand/index').default} | ||
component={AsyncShorthandPrototype} | ||
/>, | ||
<DocsLayout | ||
exact | ||
key="/prototype-employee-card" | ||
path="/prototype-employee-card" | ||
component={require('./prototypes/employeeCard/index').default} | ||
component={EmployeeCardPrototype} | ||
/>, | ||
<DocsLayout | ||
exact | ||
key="/prototype-meeting-options" | ||
path="/prototype-meeting-options" | ||
component={require('./prototypes/meetingOptions/index').default} | ||
component={MeetingOptionsPrototype} | ||
/>, | ||
<DocsLayout | ||
exact | ||
key="/prototype-search-page" | ||
path="/prototype-search-page" | ||
component={require('./prototypes/SearchPage/index').default} | ||
component={SearchPagePrototype} | ||
/>, | ||
<DocsLayout | ||
exact | ||
key="/prototype-mentions" | ||
path="/prototype-mentions" | ||
component={require('./prototypes/mentions/index').default} | ||
component={MentionsPrototype} | ||
/>, | ||
<DocsLayout | ||
exact | ||
key="/prototype-dropdowns" | ||
path="/prototype-dropdowns" | ||
component={require('./prototypes/dropdowns/index').default} | ||
component={DropdownsPrototype} | ||
/>, | ||
<DocsLayout | ||
exact | ||
key="/prototype-popups" | ||
path="/prototype-popups" | ||
component={require('./prototypes/popups/index').default} | ||
component={PopupsPrototype} | ||
/>, | ||
<DocsLayout | ||
exact | ||
key="/icon-viewer" | ||
path="/icon-viewer" | ||
component={require('./prototypes/IconViewer/index').default} | ||
component={IconViewerPrototype} | ||
/>, | ||
<DocsLayout | ||
exact | ||
key="/menu-button" | ||
path="/menu-button" | ||
component={require('./prototypes/MenuButton/index').default} | ||
component={MenuButtonPrototype} | ||
/>, | ||
<DocsLayout | ||
exact | ||
key="/prototype-alerts" | ||
path="/prototype-alerts" | ||
component={require('./prototypes/alerts/index').default} | ||
component={AlertsPrototype} | ||
/>, | ||
]} | ||
<DocsLayout exact path="/faq" component={FAQ} /> | ||
|
This file contains 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 |
---|---|---|
|
@@ -15,8 +15,25 @@ export const examplePlaygroundContext = require.context( | |
/** | ||
* The Webpack Context for doc site example sources. | ||
*/ | ||
export const exampleSourcesContext = require.context( | ||
// It's required for a hot reload | ||
// eslint-disable-next-line import/no-mutable-exports | ||
export let exampleSourcesContext = require.context( | ||
'docs/src/exampleSources/', | ||
true, | ||
/.source.json$/, | ||
) | ||
|
||
// ---------------------------------------- | ||
// HMR | ||
// ---------------------------------------- | ||
|
||
if (__DEV__) { | ||
// When the application source code changes, re-render the whole thing. | ||
if (module.hot) { | ||
// We need this to catch cases unhandled by RHL | ||
// https://github.com/webpack/webpack/issues/834#issuecomment-76590576 | ||
module.hot.accept(exampleSourcesContext.id, () => { | ||
exampleSourcesContext = require.context('docs/src/exampleSources/', true, /.source.json$/) | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Context should be updated separately. |
||
} | ||
} |
This file contains 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 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.
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.
We don't need
Provider.Consumer
more there