Skip to content
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

🐛 Fixed "Cannot read property 'feature_image' of undefined" #10602

Merged
merged 4 commits into from
Mar 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions core/server/data/meta/context_object.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,19 @@ function getContextObject(data, context) {
// @TODO: meta layer is very broken, it's really hard to understand what it's doing
// The problem is that handlebars root object is structured differently. Sometimes the object is flat on data
// and sometimes the object is part of a key e.g. data.post. This needs to be prepared at the very first stage and not in each helper.
if (_.includes(context, 'page') || _.includes(context, 'amp') && data.post) {
if ((_.includes(context, 'page') || _.includes(context, 'amp')) && data.post) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing braaaces 🤬

chosenContext = data.post;
} else if (_.includes(context, 'post') && data.post) {
chosenContext = data.post;
} else if (_.includes(context, 'page') && data.page) {
chosenContext = data.page;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this extra case to ensure the data is returned for the case of using data: page.slug.
Dynamic routing has added a lot of extra cases for the meta layer, refs #10082.

} else if (data[context]) {
// @NOTE: This is confusing as hell. It tries to get data[['author']], which works, but coincidence?
chosenContext = data[context];
} else {
}

// Super fallback.
if (!chosenContext) {
chosenContext = blog;
}

Expand Down
36 changes: 34 additions & 2 deletions core/test/regression/site/site_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2625,10 +2625,28 @@ describe('Integration - Web - Site', function () {
});
});

describe('collection with data key', function () {
describe('collection/routes with data key', function () {
before(function () {
sinon.stub(settingsService, 'get').returns({
routes: {},
routes: {
'/my-page/': {
data: {
query: {
page: {
controller: 'pagesPublic',
resource: 'pages',
type: 'read',
options: {
slug: 'static-page-test'
}
}
},
router: {
pages: [{redirect: true, slug: 'static-page-test'}]
}
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use case was not covered in dynamic routing regression test. Now it's there.
It errors on master

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤓

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm.. Tried it on master, didn't error 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It hangs!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You were right 👍 my 🅱️

},

collections: {
'/food/': {
Expand Down Expand Up @@ -2759,6 +2777,20 @@ describe('Integration - Web - Site', function () {
response.statusCode.should.eql(200);
});
});

it('serve my-page', function () {
const req = {
secure: true,
method: 'GET',
url: '/my-page/',
host: 'example.com'
};

return testUtils.mocks.express.invoke(app, req)
.then(function (response) {
response.statusCode.should.eql(200);
});
});
});
});

Expand Down
9 changes: 9 additions & 0 deletions core/test/unit/data/meta/context_object_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ describe('getContextObject', function () {
contextObject.should.eql(data.post);
});

it('should return page', function () {
data = {page: {id: 2}};
context = ['news', 'page'];
contextObject = getContextObject(data, context);

should.exist(contextObject);
contextObject.should.eql(data.page);
});

describe('override blog', function () {
before(function () {
sinon.stub(settingsCache, 'get').callsFake(function (key) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{ghost_head}}