Skip to content

Convert existing comments to be statically rendered. #3295

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

Closed
miketaylr opened this issue Apr 22, 2020 · 2 comments
Closed

Convert existing comments to be statically rendered. #3295

miketaylr opened this issue Apr 22, 2020 · 2 comments

Comments

@miketaylr
Copy link
Member

miketaylr commented Apr 22, 2020

Follow up to #3281

This may or may not be desirable, since it will require us to block on another request. Perhaps dynamic is the way to go here. 🤔

But if we want to create an archive, we will at least need a method that allows for static comment rendering, so it could be optional.

@miketaylr
Copy link
Member Author

miketaylr commented May 4, 2020

Here's how comments currently work:

For an issue, initialize the CommentsCollection here:

this.comments = new issues.CommentsCollection({ pageNumber: 1 });

If there are any comments on the issue, here is where we fetch them:

// If there are any comments, go fetch the model data
if (this.issue.get("commentNumber") > 0) {
this.comments
.fetch({ headers: { Accept: "application/json" } })
.done(
_.bind(function (response) {
this.addExistingComments();
this.comments.bind("add", _.bind(this.addComment, this));
// If there's a #hash pointing to a comment (or elsewhere)
// scrollTo it.
if (location.hash !== "") {
var _id = $(location.hash);
window.scrollTo(0, _id.offset().top);
}
if (response[0].lastPageNumber > 1) {
this.getRemainingComments(++response[0].lastPageNumber);
}
}, this)
)
.fail(function () {
var msg =
"There was an error retrieving issue comments. Please reload to try again.";
wcEvents.trigger("flash:error", {
message: msg,
timeout: 4000,
});
});
}
},

Then if there's more than 30 comments (super rare, I would imagine), grab the rest:

getRemainingComments: function (count) {
//The first 30 comments for page 1 has already been loaded.
//If more than 30 comments are there the remaining comments are rendered in sets of 30
//in consecutive pages
_.each(
_.bind(
_.range(2, count),
function (i) {
this.comments.fetchPage({
pageNumber: i,
headers: { Accept: "application/json" },
});
},
this
)
);
},

This is where we render an individual comment (this gets called for each existing comment, and for new comments):

addComment: function (comment) {
// if there's a nsfw label, add the relevant class.
var view = new issues.CommentView({ model: comment });
var commentElm = view.render().$el;
$(".js-Issue-commentList").append(commentElm);
_.each(commentElm.find("code"), function (elm) {
Prism.highlightElement(elm);
});
if (this._isNSFW) {
_.each(commentElm.find("img"), function (elm) {
$(elm).closest("p").addClass("issue-details-nsfw");
});
}
},

@miketaylr
Copy link
Member Author

Maybe a place to start here is to create the ability to fetch 30 pre-rendered comments at a time, returned as HTML we can add to the page after the initial load.

I'd like to avoid building 2 entirely different comment loading solutions, where possible (because they're likely to fall out of sync). I don't think it's entirely unavoidable, but something to aim for.

miketaylr pushed a commit that referenced this issue May 15, 2020
Or at least, the first 100. Future work will make sure we get all of it.
miketaylr pushed a commit that referenced this issue May 15, 2020
Or at least, the first 100. Future work will make sure we get all of it.
miketaylr pushed a commit that referenced this issue May 16, 2020
Or at least, the first 100. Future work will make sure we get all of it.
miketaylr pushed a commit that referenced this issue May 16, 2020
Or at least, the first 100. Future work will make sure we get all of it.
miketaylr pushed a commit that referenced this issue May 16, 2020
We can get rid of the clientside handling of all of this now.
miketaylr pushed a commit that referenced this issue May 16, 2020
miketaylr pushed a commit that referenced this issue May 17, 2020
It's no longer to test this the way that we did. We'll have to
rely on mocked unit tests (which is fine, this just tested that
some data was injected to the frontend, it never tested if it worked
on the GitHub side of things)
miketaylr pushed a commit that referenced this issue May 17, 2020
We can get rid of the clientside handling of all of this now.
miketaylr pushed a commit that referenced this issue May 17, 2020
miketaylr pushed a commit that referenced this issue May 17, 2020
It's no longer to test this the way that we did. We'll have to
rely on mocked unit tests (which is fine, this just tested that
some data was injected to the frontend, it never tested if it worked
on the GitHub side of things)
miketaylr pushed a commit that referenced this issue May 17, 2020
miketaylr pushed a commit that referenced this issue May 18, 2020
We can get rid of the clientside handling of all of this now.
miketaylr pushed a commit that referenced this issue May 18, 2020
miketaylr pushed a commit that referenced this issue May 18, 2020
It's no longer to test this the way that we did. We'll have to
rely on mocked unit tests (which is fine, this just tested that
some data was injected to the frontend, it never tested if it worked
on the GitHub side of things)
miketaylr pushed a commit that referenced this issue May 18, 2020
miketaylr pushed a commit that referenced this issue May 20, 2020
We can get rid of the clientside handling of all of this now.
miketaylr pushed a commit that referenced this issue May 20, 2020
miketaylr pushed a commit that referenced this issue May 20, 2020
This file will be returned when POSTing a new comment in test mode,
so our existing functional tests can pass. When doing a GET, it will
serve /tests/fixtures/api/issues/100/comments.38e6a9ddcea3ef150105b48bcd1c18f3.json
because it has a ?per_page=100 param.
miketaylr pushed a commit that referenced this issue May 20, 2020
miketaylr pushed a commit that referenced this issue May 20, 2020
Now we rely on everything coming back from GitHub before rendering,
so there's no more need for this.
miketaylr pushed a commit that referenced this issue May 20, 2020
miketaylr pushed a commit that referenced this issue May 20, 2020
miketaylr pushed a commit that referenced this issue May 20, 2020
miketaylr pushed a commit that referenced this issue May 20, 2020
soniasingla pushed a commit to soniasingla/webcompat.com that referenced this issue Jun 13, 2020
Or at least, the first 100. Future work will make sure we get all of it.
soniasingla pushed a commit to soniasingla/webcompat.com that referenced this issue Jun 13, 2020
soniasingla pushed a commit to soniasingla/webcompat.com that referenced this issue Jun 13, 2020
soniasingla pushed a commit to soniasingla/webcompat.com that referenced this issue Jun 13, 2020
We can get rid of the clientside handling of all of this now.
soniasingla pushed a commit to soniasingla/webcompat.com that referenced this issue Jun 13, 2020
soniasingla pushed a commit to soniasingla/webcompat.com that referenced this issue Jun 13, 2020
soniasingla pushed a commit to soniasingla/webcompat.com that referenced this issue Jun 13, 2020
This file will be returned when POSTing a new comment in test mode,
so our existing functional tests can pass. When doing a GET, it will
serve /tests/fixtures/api/issues/100/comments.38e6a9ddcea3ef150105b48bcd1c18f3.json
because it has a ?per_page=100 param.
soniasingla pushed a commit to soniasingla/webcompat.com that referenced this issue Jun 13, 2020
soniasingla pushed a commit to soniasingla/webcompat.com that referenced this issue Jun 13, 2020
soniasingla pushed a commit to soniasingla/webcompat.com that referenced this issue Jun 13, 2020
soniasingla pushed a commit to soniasingla/webcompat.com that referenced this issue Jun 13, 2020
soniasingla pushed a commit to soniasingla/webcompat.com that referenced this issue Jun 13, 2020
Now we rely on everything coming back from GitHub before rendering,
so there's no more need for this.
soniasingla pushed a commit to soniasingla/webcompat.com that referenced this issue Jun 13, 2020
soniasingla pushed a commit to soniasingla/webcompat.com that referenced this issue Jun 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant