Skip to content
This repository was archived by the owner on Oct 11, 2022. It is now read-only.

Conversation

@mxstbr
Copy link
Contributor

@mxstbr mxstbr commented Aug 13, 2018

Status

  • WIP
  • Ready for review
  • Needs testing

Deploy after merge (delete what needn't be deployed)

  • hyperion (frontend)

Related issues (delete if you don't know of any)
Closes #2770

Implements nicer thread URLs based on the scheme /community/channel/slug(threadTitle)~threadId. Note that I had to use tilde ~ as the delimiter between slug and id because our thread id's include hyphens, so we can't use that, and the only other options were dots . or underscores _ and both of those look worse imo.

TODO

  • Render threads at /:community/:channel/:id
  • Try and figure out if we can do /:community/:channel/:threadSlug-:threadId or something like that
  • Redirect old route to new route
    • ...from frontend JS
    • ...from hyperion? the frontend redirect also works on SSR, so we're good here
  • Redirect URLs without the title slug to the URL with the title slug
  • Make sure the canonical URL includes the title slug
  • Fix param redirect? this is already handled by the redirect from the /thread/:id routes to the new ones. Redirecting the param to the new routes automatically would require hyperion to be connected to the db, which it currently isn't, so it's imo not worth it.
  • Replace all links in src to /thread/xyz with links to /community/channel/xyz
    • Fix "Copy link to message to clipboard"
    • Fix nested community and channel slugs

@mxstbr mxstbr requested a review from brianlovin August 13, 2018 09:19
@mxstbr
Copy link
Contributor Author

mxstbr commented Aug 13, 2018

@brianlovin I think this is ready apart from replacing all links to /thread/${id} with the new format! It handles all the following cases:

  • /thread/:id
  • /community/channel/id
  • /community/channel/wrong-slug~id
  • /community/wrongchannel/slug~id (so if the thread is moved the URL redirects automatically!)
  • /wrongcommunity/wrongchannel/wrongslug~id
  • etc.

This all works because we literally ignore everything except for the ID, and then redirect to the correct URL once loaded. 😜 That makes everything work, including moving threads between channels! Can you think of anything else we might need to handle apart from the link updates?

@brianlovin
Copy link
Contributor

Really interesting solution, thanks for digging into this! It's interesting because we don't actually care about the url at all when performing the fetch, but the canonical url will be super helpful with SEO. In your solution, if I'm reading this correctly, it seems like moving channels won't affect any url at all - if someone shares an old :communityId/:oldChannelId/:threadTitle~:threadId url, it'll still render the right thread even if the new canonical url is :communityId/:newChannelId/:threadTitle~:threadId...

So this seems like good work, let's give it a go! Want to update all the src usages to the new system, and investigate those CI failures?

Also: am I correct that this won't change the ?thread= url behavior for the slider?

@mxstbr
Copy link
Contributor Author

mxstbr commented Aug 13, 2018

Also: am I correct that this won't change the ?thread= url behavior for the slider?

Nope, it won't change anything in the slider or inbox. (or at least shouldn't...)

Want to update all the src usages to the new system, and investigate those CI failures?

Will finish this off tomorrow!

if someone shares an old :communityId/:oldChannelId/:threadTitle~:threadId url, it'll still render the right thread even if the new canonical url is :communityId/:newChannelId/:threadTitle~:threadId...

It will render the thread, but then redirect to /community/newChannel/threadTitle~threadId, if that makes sense. I just always redirect to the canonical URL if we're at a different one to circumvent that set of problems entirely.

@brianlovin
Copy link
Contributor

It will render the thread, but then redirect to /community/newChannel/threadTitle~threadId, if that makes sense. I just always redirect to the canonical URL if we're at a different one to circumvent that set of problems entirely.

Awesome, great work man!

@mxstbr
Copy link
Contributor Author

mxstbr commented Aug 20, 2018

This will definitely need a lot of testing on alpha before shipping!

@brianlovin
Copy link
Contributor

Looks like maybe that failing e2e test has something to do with privacy and permissions on private threads?

@mxstbr
Copy link
Contributor Author

mxstbr commented Aug 21, 2018

Ah yeah of course, private threads can't redirect to the proper URL since the data doesn't exist 🤦‍♂️ Will dig into private thread handling!

@mxstbr
Copy link
Contributor Author

mxstbr commented Aug 22, 2018

Aha tests still failing because I forgot to forward ?m params, good catch e2e tests good catch! Fixed in latest commit, let's see if I forgot another edge case or not 🤞

@mxstbr
Copy link
Contributor Author

mxstbr commented Aug 22, 2018

Yesss now I think I've actually covered all edge cases! 💯 This should also be ready for testing on alpha

@mxstbr
Copy link
Contributor Author

mxstbr commented Aug 22, 2018

@brianlovin this is ready to ship to hyperion.alpha.spectrum.chat tomorrow after you give it a final review! 🙏

@mxstbr
Copy link
Contributor Author

mxstbr commented Aug 22, 2018

Actually I might be able to make - work as a delimiter, since UUIDs have a consistent structure so we can have a regexp that checks for two or three of them at the end to get the ID!

Going to try that, that'd be much nicer than ~

@brianlovin
Copy link
Contributor

Going to try that, that'd be much nicer than ~

Sounds good, I'll hang tight!

New thread urls look like this:

/spectrum/general/the-thread-is-too-small-mnbkzlqp-jkld-utei-tqg4-jliaeti1itud

Much better than with the tilde 👍
@mxstbr
Copy link
Contributor Author

mxstbr commented Aug 24, 2018

Latest commit makes it work without the tilde! Now thread URLs look like this:

  • /spectrum/general/the-thread-is-too-small-66df15e9-17aa-4f7b-ab9f-0021ca881a88
  • /figma/feedback/i-really-really-miss-the-opacity-option-for-gradients-fff23ef5-f29f-4d6e-9614-db30b23e1f99

😍😍😍

This is ready for a review, and then we should get it on alpha for some solid testing!

@brianlovin
Copy link
Contributor

Hm looks like the e2e tests for the thread view are failing. I like where this is going though!

src/routes.js Outdated
// - /id-123-123-123-id => id-123-123-123-id, easy start that works
// - /some-custom-slug-id-123-123-123-id => id-123-123-123-id, custom slug also works
// - /-id-123-123-123-id => id-123-123-123-id, empty custom slug also works
path="/:communitySlug/:channelSlug/(.*?)(\w*-\w*-\w*-\w*-\w*)"
Copy link
Contributor

Choose a reason for hiding this comment

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

Fairly sure this will break for all firebase-imported threads from way back in the day.

@mxstbr
Copy link
Contributor Author

mxstbr commented Aug 28, 2018

Shit that's such a good catch @brianlovin, I totally forgot about those! 🤦‍♂️ Ugh.

Been brewing over how to solve that for the last couple days, here are some options I came up with:

  1. Store a slug field on every thread in the database and expose it via the GraphQL API, both as an arg for queries (thread(slug: "")) and on the Thread object (Thread.slug: LowercaseString!).
  2. Use the ~ delimited version
  3. Create a migration to move all old, non-UUID threads to UUID's

What are your thoughts on either of these?

@brianlovin
Copy link
Contributor

Store a slug field on every thread in the database and expose it via the GraphQL API

This sounds pretty risky - I like that your current version doesn't actually care about the slug, since it just uses the uuid for the lookup. Storing a slug and using it for lookups seems more fragile and can become stale if threads are edited.

Use the ~ delimited version

This seems...easiest? Just slightly less aesthetic.

Create a migration to move all old, non-UUID threads to UUID's

This sounds very not fun. Backfilling the usersThreads records to use updated uuids sounds like a pita and prone to bugs. Although, technically, this would be the best solution for future-proofing id patterns :/

@mxstbr
Copy link
Contributor Author

mxstbr commented Aug 29, 2018

Create a migration to move all old, non-UUID threads to UUID's

We have 1105 threads that have Firebase-style IDs:

db.table('threads').filter(
  db.not(db.row('id').match("^\\w{8}-\\w{4}-\\w{4}-\\w{4}-\\w{12}$"))
).count()

// => 1105

Actually, what's going to block this is the way we store notifications. Those have the thread IDs hardcoded in the payload string and there isn't much we can do about it 😕 Ugh

@mxstbr
Copy link
Contributor Author

mxstbr commented Aug 29, 2018

Reverted back to ~ version, it seems like the best option even if not quite as aesthetically pleasing..

@brianlovin
Copy link
Contributor

Damn. I mean, we could always just burn notifications to the ground and redo those :P

@mxstbr
Copy link
Contributor Author

mxstbr commented Nov 5, 2018

Clicked to different threads from their timestamps from the slider, got this:

screenshot 2018-11-05 at 15 23 58

First, that shouldn't work. Second, that shouldn't happen 😅

@mxstbr
Copy link
Contributor Author

mxstbr commented Nov 19, 2018

@brianlovin this has been tested on alpha and I couldn't find any more bugs, so I'm inclined to say this is ready to ship! 🎉

@brianlovin
Copy link
Contributor

Sounds good to me! I'll do a cut today

@brianlovin brianlovin merged commit 017a275 into alpha Nov 19, 2018
@brianlovin brianlovin deleted the nicer-thread-slugs branch November 19, 2018 17:39
@brianlovin
Copy link
Contributor

I found a place this breaks locally, will investigate

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants