-
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
[v2] fix find-page #5228
[v2] fix find-page #5228
Changes from 1 commit
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 |
---|---|---|
|
@@ -10,7 +10,7 @@ let hasFetched = Object.create(null) | |
let syncRequires = {} | ||
let asyncRequires = {} | ||
let jsonDataPaths = {} | ||
let pathPrefix = `` | ||
let pathPrefix = `/` | ||
let fetchHistory = [] | ||
let fetchingPageResourceMapPromise = null | ||
let fetchedPageResourceMap = false | ||
|
@@ -48,7 +48,7 @@ const fetchResource = resourceName => { | |
if (resourceName in jsonStore) { | ||
resolve(jsonStore[resourceName]) | ||
} else { | ||
const url = `${pathPrefix ? pathPrefix : `/`}static/d/${ | ||
const url = `${pathPrefix}static/d/${ | ||
jsonDataPaths[resourceName] | ||
}.json` | ||
var req = new XMLHttpRequest() | ||
|
@@ -156,7 +156,6 @@ const sortResourcesByCount = (a, b) => { | |
} | ||
|
||
let findPage | ||
let pages = [] | ||
let pathScriptsCache = {} | ||
let resourcesArray = [] | ||
let mountOrder = 1 | ||
|
@@ -165,19 +164,14 @@ const queue = { | |
empty: () => { | ||
resourcesCount = Object.create(null) | ||
resourcesArray = [] | ||
pages = [] | ||
pathPrefix = `` | ||
pathPrefix = `/` | ||
}, | ||
|
||
addPagesArray: newPages => { | ||
pages = newPages | ||
if ( | ||
typeof __PREFIX_PATHS__ !== `undefined` && | ||
typeof __PATH_PREFIX__ !== `undefined` | ||
) { | ||
if (__PREFIX_PATHS__ === true) pathPrefix = `${__PATH_PREFIX__}/` | ||
if (__PREFIX_PATHS__) { | ||
pathPrefix = `${__PATH_PREFIX__}/` | ||
} | ||
findPage = pageFinderFactory(newPages, pathPrefix) | ||
findPage = pageFinderFactory(newPages, pathPrefix.slice(0, -1)) | ||
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. Why not just use 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. because we use 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. ah right :-) You did cover this in the description 👍to that |
||
}, | ||
addDevRequires: devRequires => { | ||
syncRequires = devRequires | ||
|
@@ -191,7 +185,7 @@ const queue = { | |
dequeue: () => resourcesArray.pop(), | ||
enqueue: rawPath => { | ||
// Check page exists. | ||
const path = stripPrefix(rawPath, pathPrefix) | ||
const path = stripPrefix(rawPath, pathPrefix.slice(0, -1)) | ||
|
||
let page = findPage(path) | ||
|
||
|
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.
Removing this
if
seems to make related tests unhappy ( https://travis-ci.org/gatsbyjs/gatsby/jobs/374034245#L1484 ) :(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.
but we don't do this check in other places, I just want to make them consistency, what about change the test code here https://github.com/gatsbyjs/gatsby/blob/v2/packages/gatsby/cache-dir/__tests__/loader.js#L5-L12?
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 should reset them to the proper values like
''
andfalse
instead ofundefined
, also I think we can drop the workaround for Node v6, do we still support that node version?I see we still support v6 in the
package.json
, I think we can drop the support for thatThere 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.
Yeah, we can adjust tests, sure. Just keep in mind that we should check tests (some of them are still failing on v2 but we are working to get them all of the passing again - just let's not break tests that are already passing - either adjust code or tests - whichever make sense)
We want to support node 6 (related comment chain - #2641 (comment) ).
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.
Thanks for clarifying
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.
tests are passing now