hometown/app/javascript/mastodon/components
aschmitz 669fe9ee06 Change IDs to strings rather than numbers in API JSON output (#5019)
* Fix JavaScript interface with long IDs

Somewhat predictably, the JS interface handled IDs as numbers, which in
JS are IEEE double-precision floats. This loses some precision when
working with numbers as large as those generated by the new ID scheme,
so we instead handle them here as strings. This is relatively simple,
and doesn't appear to have caused any problems, but should definitely
be tested more thoroughly than the built-in tests. Several days of use
appear to support this working properly.

BREAKING CHANGE:

The major(!) change here is that IDs are now returned as strings by the
REST endpoints, rather than as integers. In practice, relatively few
changes were required to make the existing JS UI work with this change,
but it will likely hit API clients pretty hard: it's an entirely
different type to consume. (The one API client I tested, Tusky, handles
this with no problems, however.)

Twitter ran into this issue when introducing Snowflake IDs, and decided
to instead introduce an `id_str` field in JSON responses. I have opted
to *not* do that, and instead force all IDs to 64-bit integers
represented by strings in one go. (I believe Twitter exacerbated their
problem by rolling out the changes three times: once for statuses, once
for DMs, and once for user IDs, as well as by leaving an integer ID
value in JSON. As they said, "If you’re using the `id` field with JSON
in a Javascript-related language, there is a very high likelihood that
the integers will be silently munged by Javascript interpreters. In most
cases, this will result in behavior such as being unable to load or
delete a specific direct message, because the ID you're sending to the
API is different than the actual identifier associated with the
message." [1]) However, given that this is a significant change for API
users, alternatives or a transition time may be appropriate.

1: https://blog.twitter.com/developer/en_us/a/2011/direct-messages-going-snowflake-on-sep-30-2011.html

* Additional fixes for stringified IDs in JSON

These should be the last two. These were identified using eslint to try
to identify any plain casts to JavaScript numbers. (Some such casts are
legitimate, but these were not.)

Adding the following to .eslintrc.yml will identify casts to numbers:

~~~
  no-restricted-syntax:
  - warn
  - selector: UnaryExpression[operator='+'] > :not(Literal)
    message: Avoid the use of unary +
  - selector: CallExpression[callee.name='Number']
    message: Casting with Number() may coerce string IDs to numbers
~~~

The remaining three casts appear legitimate: two casts to array indices,
one in a server to turn an environment variable into a number.

* Back out RelationshipsController Change

This was made to make a test a bit less flakey, but has nothing to
do with this branch.

* Change internal streaming payloads to stringified IDs as well

Per
https://github.com/tootsuite/mastodon/pull/5019#issuecomment-330736452
we need these changes to send deleted status IDs as strings, not
integers.
2017-09-20 14:53:48 +02:00
..
account.js Change IDs to strings rather than numbers in API JSON output (#5019) 2017-09-20 14:53:48 +02:00
attachment_list.js Use Class and Property Decorators (#3730) 2017-06-23 19:36:54 +02:00
autosuggest_textarea.js Change IDs to strings rather than numbers in API JSON output (#5019) 2017-09-20 14:53:48 +02:00
avatar_overlay.js Refactor Avatar and AvatarOverlay to have 'account' as prop instead of src and staticSrc (#4526) 2017-08-07 19:44:55 +02:00
avatar.js Refactor Avatar and AvatarOverlay to have 'account' as prop instead of src and staticSrc (#4526) 2017-08-07 19:44:55 +02:00
button.js Use Class and Property Decorators (#3730) 2017-06-23 19:36:54 +02:00
collapsable.js Improve eslint rules (#3147) 2017-05-20 17:31:47 +02:00
column_back_button_slim.js Use Class and Property Decorators (#3730) 2017-06-23 19:36:54 +02:00
column_back_button.js Improve accessibility (part 7) (#4457) 2017-07-31 00:18:15 +02:00
column_header.js Improve accessibility (part 3) (#4405) 2017-07-28 00:54:48 +02:00
column.js Fix the usages of Detect Passive Events (#4749) 2017-08-31 11:20:54 +02:00
display_name.js feat: Cache status height to avoid expensive renders (#4439) 2017-08-07 20:32:03 +02:00
dropdown_menu.js Improve accessibility (part 6) (#4435) 2017-07-29 01:58:53 +02:00
extended_video_player.js Quit overwriting style of extended-video-player (#4237) 2017-07-17 19:05:29 +02:00
icon_button.js Improve accessibility (part 6) (#4435) 2017-07-29 01:58:53 +02:00
intersection_observer_article.js Fix height cache (#4909) 2017-09-13 10:24:33 +02:00
load_more.js Fix invisible load more button (#4962) 2017-09-16 00:32:43 +02:00
loading_indicator.js Add loading indicator animation (#4316) 2017-07-23 20:28:18 +02:00
media_gallery.js Fix hasSize condition in secSet and sizes. (#4969) 2017-09-16 15:00:01 +02:00
missing_indicator.js Replace sprockets/browserify with Webpack (#2617) 2017-05-03 02:04:16 +02:00
permalink.js Redesign the landing page, mount public timeline on it (#4122) 2017-07-11 15:27:59 +02:00
relative_timestamp.js Use Class and Property Decorators (#3730) 2017-06-23 19:36:54 +02:00
scrollable_list.js Fix invisible load more button (#4962) 2017-09-16 00:32:43 +02:00
setting_text.js Improve accessibility (part 3) (#4405) 2017-07-28 00:54:48 +02:00
status_action_bar.js Change IDs to strings rather than numbers in API JSON output (#5019) 2017-09-20 14:53:48 +02:00
status_content.js feat: Cache status height to avoid expensive renders (#4439) 2017-08-07 20:32:03 +02:00
status_list.js Generalized the infinite scrollable list (#4697) 2017-08-28 22:23:44 +02:00
status.js Change IDs to strings rather than numbers in API JSON output (#5019) 2017-09-20 14:53:48 +02:00
video_player.js Use <button> instead of <div role="button"> (#4835) 2017-09-07 16:18:41 +02:00