-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Initialize a new HTTP client for each web request #1237
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
487f19b
Initialize a new HTTP client for each web request
koistya 0b1e1e4
Fix ESLint warning in Html.js
koistya 6c1b54c
Make createFetch more readable
koistya e0222a3
Update docs/data-fetching.md
koistya 19b555e
Code style fixes
koistya 0dcd16e
Code style fixes
koistya 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
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
File renamed without changes.
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 |
---|---|---|
|
@@ -12,10 +12,11 @@ import ReactDOM from 'react-dom'; | |
import FastClick from 'fastclick'; | ||
import queryString from 'query-string'; | ||
import { createPath } from 'history/PathUtils'; | ||
import history from './core/history'; | ||
import App from './components/App'; | ||
import { updateMeta } from './core/DOMUtils'; | ||
import { ErrorReporter, deepForceUpdate } from './core/devUtils'; | ||
import createFetch from './createFetch'; | ||
import history from './history'; | ||
import { updateMeta } from './DOMUtils'; | ||
import { ErrorReporter, deepForceUpdate } from './devUtils'; | ||
|
||
/* eslint-disable global-require */ | ||
|
||
|
@@ -29,6 +30,10 @@ const context = { | |
const removeCss = styles.map(x => x._insertCss()); | ||
return () => { removeCss.forEach(f => f()); }; | ||
}, | ||
// Universal HTTP client | ||
fetch: createFetch({ | ||
baseUrl: window.App.apiUrl, | ||
}), | ||
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. add |
||
}; | ||
|
||
// Switch off the native scroll restoration behavior and handle it manually | ||
|
@@ -87,7 +92,7 @@ FastClick.attach(document.body); | |
const container = document.getElementById('app'); | ||
let appInstance; | ||
let currentLocation = history.location; | ||
let router = require('./core/router').default; | ||
let router = require('./router').default; | ||
|
||
// Re-render the app when window.location changes | ||
async function onLocationChange(location, action) { | ||
|
@@ -109,6 +114,7 @@ async function onLocationChange(location, action) { | |
const route = await router.resolve({ | ||
path: location.pathname, | ||
query: queryString.parse(location.search), | ||
fetch: context.fetch, | ||
}); | ||
|
||
// Prevent multiple page renders during the routing process | ||
|
@@ -161,8 +167,8 @@ if (__DEV__) { | |
|
||
// Enable Hot Module Replacement (HMR) | ||
if (module.hot) { | ||
module.hot.accept('./core/router', () => { | ||
router = require('./core/router').default; | ||
module.hot.accept('./router', () => { | ||
router = require('./router').default; | ||
|
||
if (appInstance) { | ||
try { | ||
|
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
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.
Example here is on router. But I believe users are importing fetch on more nested components so HoC implementation and React HoC component
withFetch()
which correctly bridgecontext
will be needed for users.