AprilSylph / XKit-Rewritten

🧰 The enhancement suite for Tumblr's new web interface
GNU General Public License v3.0
274 stars 44 forks source link

Parse `data-timeline-id` on Tumblr's new timeline component #1482

Closed marcustyphoon closed 5 days ago

marcustyphoon commented 3 weeks ago

Description

Tumblr has a new internal TimelineV2 component that changes some attributes we use to detect timelines and which posts a timeline is on. There is currently an incomplete rollout of this migration, partially behind some feature flags.

This:

I experimented with a) generating timeline filter functions and timeline css selectors automatically from the same source data and b) making that source data exhaustive in #1485. It was interesting but kind of bad. It does make this diff look extremely boilerplate-y by comparison, though.

Resolves #1488. Resolves #1480.

Testing steps

If I've left this line in the PR description I haven't exhaustively tested this yet; keep that in mind.

Tests should include having endless scrolling on/off, and having feature flags on/off. I will not post my method for toggling feature flags in production here but it's very easy.

I have also been running a user style to make things quick and easy:

[data-timeline-id] {
  border-top: 2px dashed red;
}

[data-timeline] {
  border-top: 2px dashed green;
}

[data-timeline][data-timeline-id] {
  border-top: 2px dashed blue;
}

[data-timeline-id]::before {
  display: block;
  content: attr(data-timeline-id);
  color: red;
  margin: 1ch;
}

[data-timeline]::before {
  display: block;
  content: attr(data-timeline);
  color: green;
  margin: 1ch;
}
marcustyphoon commented 2 weeks ago

Aside: here's a fun use of the fairly-new groupBy global, for... well, "performance", in theory. Why process each timeline element for every post that gets added instead of processing each one once?

Well, because performing a simple regex, even from a string, is so fast it doesn't show up in the chromium profiler, and this code is way too long (Maps are so clunky) and requires us to bump minimum browser versions, is why. Not worth it.

  if (timeline) {
    const timelineFilters = [timeline].flat().filter(Boolean);

    const postsByTimeline = Map.groupBy(
      postElements,
      postElement => postElement.closest(timelineSelector)
    );

    const filtered = [...postsByTimeline.entries()]
      .map(([timelineElement, postElements]) =>
        timelineElement &&
        timelineFilters.some(timelineFilter => timelineFilter(timelineElement))
          ? postElements
          : []
      )
      .flat();

    postElements = filtered;
  }
marcustyphoon commented 1 week ago
marcustyphoon commented 5 days ago

Haven't! Will do that.

AprilSylph commented 5 days ago

Also, is there anything else you want me to look at before putting together the v1.0.0 release?

marcustyphoon commented 5 days ago

I do have a category of small diffs that fix regressions or potential pitfalls that I use the bugfix label for (that could also include #1486, I guess). Could take a glance at those and see if any look important to prioritize to you!