-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
feat(gatsby): Enable develop SSR for everyone #29251
Changes from all commits
4ab0497
d8ffc26
9a64dae
47fed42
d1e7cb3
b67ef0c
d3e6d70
6831d7a
841f111
906c612
92eb6ea
98f35bc
24460ac
aee5ab9
94d7f6f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -145,12 +145,31 @@ const ConditionalFastRefreshOverlay = ({ children }) => { | |
return <React.Fragment>{children}</React.Fragment> | ||
} | ||
|
||
export default () => ( | ||
<ConditionalFastRefreshOverlay> | ||
<StaticQueryStore>{WrappedRoot}</StaticQueryStore> | ||
{process.env.GATSBY_EXPERIMENTAL_QUERY_ON_DEMAND && | ||
process.env.GATSBY_QUERY_ON_DEMAND_LOADING_INDICATOR === `true` && ( | ||
<LoadingIndicatorEventHandler /> | ||
)} | ||
</ConditionalFastRefreshOverlay> | ||
) | ||
class RootComponent extends React.Component { | ||
constructor(props) { | ||
super(props) | ||
this.state = { | ||
hasRendered: false, | ||
} | ||
} | ||
componentDidMount() { | ||
this.setState({ hasRendered: true }) | ||
} | ||
render() { | ||
if (this.state.hasRendered) { | ||
return ( | ||
<ConditionalFastRefreshOverlay> | ||
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. The overlays are client-only so we don't render them initially to avoid React saying there's hydration problems |
||
<StaticQueryStore>{WrappedRoot}</StaticQueryStore> | ||
{process.env.GATSBY_EXPERIMENTAL_QUERY_ON_DEMAND && | ||
process.env.GATSBY_QUERY_ON_DEMAND_LOADING_INDICATOR === `true` && ( | ||
<LoadingIndicatorEventHandler /> | ||
)} | ||
</ConditionalFastRefreshOverlay> | ||
) | ||
} else { | ||
return <StaticQueryStore>{WrappedRoot}</StaticQueryStore> | ||
} | ||
} | ||
} | ||
|
||
export default RootComponent |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,13 +10,13 @@ export const route = ({ app, program, store }): any => | |
app.get(`*`, async (req, res, next) => { | ||
trackFeatureIsUsed(`GATSBY_EXPERIMENTAL_DEV_SSR`) | ||
|
||
const pathObj = findPageByPath(store.getState(), req.path) | ||
const pathObj = findPageByPath(store.getState(), decodeURI(req.path)) | ||
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. needed for unicode paths like |
||
|
||
if (!pathObj) { | ||
return next() | ||
} | ||
|
||
await appendPreloadHeaders(req.path, res) | ||
await appendPreloadHeaders(pathObj.path, res) | ||
|
||
const htmlActivity = report.phantomActivity(`building HTML for path`, {}) | ||
htmlActivity.start() | ||
|
@@ -152,7 +152,7 @@ export const route = ({ app, program, store }): any => | |
node.js, it errored. | ||
</p> | ||
<ul> | ||
<li><strong>URL path:</strong> <code>${req.path}</code></li> | ||
<li><strong>URL path:</strong> <code>${pathObj.path}</code></li> | ||
<li><strong>File path:</strong> <code>${error.filename}</code></li> | ||
</ul> | ||
<h3>error</h3> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,8 +49,13 @@ export const restartWorker = (htmlComponentRendererPath): void => { | |
|
||
const searchFileForString = (substring, filePath): Promise<boolean> => | ||
new Promise(resolve => { | ||
const escapedSubString = substring.replace(/[.*+?^${}()|[\]\\]/g, `\\$&`) | ||
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 was causing failing tests on the development-runtime for paths like |
||
|
||
// See if the chunk is in the newComponents array (not the notVisited). | ||
const chunkRegex = RegExp(`exports.ssrComponents.*${substring}.*}`, `gs`) | ||
const chunkRegex = RegExp( | ||
`exports.ssrComponents.*${escapedSubString}.*}`, | ||
`gs` | ||
) | ||
const stream = fs.createReadStream(filePath) | ||
let found = false | ||
stream.on(`data`, function (d) { | ||
|
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.
the dev server now returns 404s