From 31d007eeb1651bac2df487a6b2f1c778d158e388 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 24 Aug 2020 15:06:31 -0500 Subject: [PATCH 1/3] Upgrade `@babel/plugin-proposal-object-rest-spread` It didn't fix my problem, but whatever --- package.json | 2 +- yarn.lock | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index e79c4356c..059d9da03 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "@babel/core": "^7.3.4", "@babel/plugin-proposal-class-properties": "^7.3.4", "@babel/plugin-proposal-decorators": "^7.3.0", - "@babel/plugin-proposal-object-rest-spread": "^7.3.4", + "@babel/plugin-proposal-object-rest-spread": "^7.11.0", "@babel/plugin-syntax-dynamic-import": "^7.2.0", "@babel/plugin-transform-react-inline-elements": "^7.2.0", "@babel/plugin-transform-react-jsx-self": "^7.2.0", diff --git a/yarn.lock b/yarn.lock index 561257434..3ce02264c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -202,6 +202,13 @@ dependencies: "@babel/types" "^7.10.1" +"@babel/helper-get-function-arity@^7.10.4": + version "7.10.4" + resolved "https://registry.yarnpkg.com/@babel/helper-get-function-arity/-/helper-get-function-arity-7.10.4.tgz#98c1cbea0e2332f33f9a4661b8ce1505b2c19ba2" + integrity sha512-EkN3YDB+SRDgiIUnNgcmiD361ti+AVbL3f3Henf6dqqUyr5dMsorno0lJWJuLhDhkI5sYEpgj6y9kB8AOU1I2A== + dependencies: + "@babel/types" "^7.10.4" + "@babel/helper-get-function-arity@^7.8.3": version "7.8.3" resolved "https://registry.yarnpkg.com/@babel/helper-get-function-arity/-/helper-get-function-arity-7.8.3.tgz#b894b947bd004381ce63ea1db9f08547e920abd5" @@ -293,6 +300,11 @@ resolved "https://registry.yarnpkg.com/@babel/helper-plugin-utils/-/helper-plugin-utils-7.10.1.tgz#ec5a5cf0eec925b66c60580328b122c01230a127" integrity sha512-fvoGeXt0bJc7VMWZGCAEBEMo/HAjW2mP8apF5eXK0wSqwLAVHAISCWRoLMBMUs2kqeaG77jltVqu4Hn8Egl3nA== +"@babel/helper-plugin-utils@^7.10.4": + version "7.10.4" + resolved "https://registry.yarnpkg.com/@babel/helper-plugin-utils/-/helper-plugin-utils-7.10.4.tgz#2f75a831269d4f677de49986dff59927533cf375" + integrity sha512-O4KCvQA6lLiMU9l2eawBPMf1xPP8xPfB3iEQw150hOVTqj/rfXz0ThTb4HEzqQfs2Bmo5Ay8BzxfzVtBrr9dVg== + "@babel/helper-regex@^7.0.0": version "7.0.0" resolved "https://registry.yarnpkg.com/@babel/helper-regex/-/helper-regex-7.0.0.tgz#2c1718923b57f9bbe64705ffe5640ac64d9bdb27" @@ -383,6 +395,11 @@ resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.10.1.tgz#5770b0c1a826c4f53f5ede5e153163e0318e94b5" integrity sha512-5vW/JXLALhczRCWP0PnFDMCJAchlBvM7f4uk/jXritBnIa6E1KmqmtrS3yn1LAnxFBypQ3eneLuXjsnfQsgILw== +"@babel/helper-validator-identifier@^7.10.4": + version "7.10.4" + resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.10.4.tgz#a78c7a7251e01f616512d31b10adcf52ada5e0d2" + integrity sha512-3U9y+43hz7ZM+rzG24Qe2mufW5KhvFg/NhnNph+i9mgCtdTCtMJuI1TMkrIUiK7Ix4PYlRF9I5dhqaLYA/ADXw== + "@babel/helper-validator-identifier@^7.9.0", "@babel/helper-validator-identifier@^7.9.5": version "7.9.5" resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.9.5.tgz#90977a8e6fbf6b431a7dc31752eee233bf052d80" @@ -488,6 +505,15 @@ "@babel/helper-plugin-utils" "^7.0.0" "@babel/plugin-syntax-json-strings" "^7.2.0" +"@babel/plugin-proposal-object-rest-spread@^7.11.0": + version "7.11.0" + resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-object-rest-spread/-/plugin-proposal-object-rest-spread-7.11.0.tgz#bd81f95a1f746760ea43b6c2d3d62b11790ad0af" + integrity sha512-wzch41N4yztwoRw0ak+37wxwJM2oiIiy6huGCoqkvSTA9acYWcPfn9Y4aJqmFFJ70KTJUu29f3DQ43uJ9HXzEA== + dependencies: + "@babel/helper-plugin-utils" "^7.10.4" + "@babel/plugin-syntax-object-rest-spread" "^7.8.0" + "@babel/plugin-transform-parameters" "^7.10.4" + "@babel/plugin-proposal-object-rest-spread@^7.3.4": version "7.3.4" resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-object-rest-spread/-/plugin-proposal-object-rest-spread-7.3.4.tgz#47f73cf7f2a721aad5c0261205405c642e424654" @@ -604,7 +630,7 @@ dependencies: "@babel/helper-plugin-utils" "^7.0.0" -"@babel/plugin-syntax-object-rest-spread@^7.8.3": +"@babel/plugin-syntax-object-rest-spread@^7.8.0", "@babel/plugin-syntax-object-rest-spread@^7.8.3": version "7.8.3" resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-object-rest-spread/-/plugin-syntax-object-rest-spread-7.8.3.tgz#60e225edcbd98a640332a2e72dd3e66f1af55871" integrity sha512-XoqMijGZb9y3y2XskN+P1wUGiVwWZ5JmoDRwx5+3GmEplNyVM2s2Dg8ILFQm8rWM48orGy5YpI5Bl8U1y7ydlA== @@ -792,6 +818,14 @@ "@babel/helper-plugin-utils" "^7.0.0" "@babel/helper-replace-supers" "^7.1.0" +"@babel/plugin-transform-parameters@^7.10.4": + version "7.10.5" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-parameters/-/plugin-transform-parameters-7.10.5.tgz#59d339d58d0b1950435f4043e74e2510005e2c4a" + integrity sha512-xPHwUj5RdFV8l1wuYiu5S9fqWGM2DrYc24TMvUiRrPVm+SM3XeqU9BcokQX/kEUe+p2RBwy+yoiR1w/Blq6ubw== + dependencies: + "@babel/helper-get-function-arity" "^7.10.4" + "@babel/helper-plugin-utils" "^7.10.4" + "@babel/plugin-transform-parameters@^7.2.0": version "7.2.0" resolved "https://registry.yarnpkg.com/@babel/plugin-transform-parameters/-/plugin-transform-parameters-7.2.0.tgz#0d5ad15dc805e2ea866df4dd6682bfe76d1408c2" @@ -1104,6 +1138,15 @@ lodash "^4.17.13" to-fast-properties "^2.0.0" +"@babel/types@^7.10.4": + version "7.11.0" + resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.11.0.tgz#2ae6bf1ba9ae8c3c43824e5861269871b206e90d" + integrity sha512-O53yME4ZZI0jO1EVGtF1ePGl0LHirG4P1ibcD80XyzZcKhcMFeCXmh4Xb1ifGBIV233Qg12x4rBfQgA+tmOukA== + dependencies: + "@babel/helper-validator-identifier" "^7.10.4" + lodash "^4.17.19" + to-fast-properties "^2.0.0" + "@babel/types@^7.3.0", "@babel/types@^7.3.4": version "7.3.4" resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.3.4.tgz#bf482eaeaffb367a28abbf9357a94963235d90ed" @@ -7426,6 +7469,11 @@ lodash@^4.15.0, lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.5, lodash@^4.7.11 resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.11.tgz#b39ea6229ef607ecd89e2c8df12536891cac9b8d" integrity sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg== +lodash@^4.17.19: + version "4.17.20" + resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.20.tgz#b44a9b6297bcb698f1c51a3545a2b3b368d59c52" + integrity sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA== + loglevel@^1.6.2: version "1.6.2" resolved "https://registry.yarnpkg.com/loglevel/-/loglevel-1.6.2.tgz#668c77948a03dbd22502a3513ace1f62a80cc372" From 57340496bc0b0b8c5cd456927a3eff3bf8773d1a Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 24 Aug 2020 15:23:05 -0500 Subject: [PATCH 2/3] Preload: dispatch preload action --- app/soapbox/actions/preload.js | 25 +++++++++++++++++++++++++ app/soapbox/containers/soapbox.js | 6 ++---- 2 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 app/soapbox/actions/preload.js diff --git a/app/soapbox/actions/preload.js b/app/soapbox/actions/preload.js new file mode 100644 index 000000000..405e144f3 --- /dev/null +++ b/app/soapbox/actions/preload.js @@ -0,0 +1,25 @@ +import { mapValues } from 'lodash'; + +const PRELOAD_IMPORT = 'PRELOAD_IMPORT'; + +// https://git.pleroma.social/pleroma/pleroma-fe/-/merge_requests/1176/diffs +const decodeUTF8Base64 = (data) => { + const rawData = atob(data); + const array = Uint8Array.from(rawData.split('').map((char) => char.charCodeAt(0))); + const text = new TextDecoder().decode(array); + return text; +}; + +const decodeData = data => + mapValues(data, base64string => + JSON.parse(decodeUTF8Base64(base64string))); + +export function preload() { + const element = document.getElementById('initial-results'); + const data = element ? JSON.parse(element.textContent) : {}; + + return { + type: PRELOAD_IMPORT, + data: decodeData(data), + }; +} diff --git a/app/soapbox/containers/soapbox.js b/app/soapbox/containers/soapbox.js index 2c7d6f85c..a2fcda9b6 100644 --- a/app/soapbox/containers/soapbox.js +++ b/app/soapbox/containers/soapbox.js @@ -14,9 +14,8 @@ import { ScrollContext } from 'react-router-scroll-4'; import UI from '../features/ui'; // import Introduction from '../features/introduction'; import { fetchCustomEmojis } from '../actions/custom_emojis'; -import { hydrateStore } from '../actions/store'; +import { preload } from '../actions/preload'; import { IntlProvider } from 'react-intl'; -import initialState from '../initial_state'; import ErrorBoundary from '../components/error_boundary'; import { fetchInstance } from 'soapbox/actions/instance'; import { fetchSoapboxConfig } from 'soapbox/actions/soapbox'; @@ -30,9 +29,8 @@ import messages from 'soapbox/locales/messages'; const validLocale = locale => Object.keys(messages).includes(locale); export const store = configureStore(); -const hydrateAction = hydrateStore(initialState); -store.dispatch(hydrateAction); +store.dispatch(preload()); store.dispatch(fetchMe()); store.dispatch(fetchInstance()); store.dispatch(fetchSoapboxConfig()); From 20f64079e05ce493edf9ada0b33e217e8c17b165 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 24 Aug 2020 15:53:38 -0500 Subject: [PATCH 3/3] Preload /api/v1/instance --- app/soapbox/actions/preload.js | 2 +- app/soapbox/reducers/instance.js | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/soapbox/actions/preload.js b/app/soapbox/actions/preload.js index 405e144f3..0f19ec721 100644 --- a/app/soapbox/actions/preload.js +++ b/app/soapbox/actions/preload.js @@ -1,6 +1,6 @@ import { mapValues } from 'lodash'; -const PRELOAD_IMPORT = 'PRELOAD_IMPORT'; +export const PRELOAD_IMPORT = 'PRELOAD_IMPORT'; // https://git.pleroma.social/pleroma/pleroma-fe/-/merge_requests/1176/diffs const decodeUTF8Base64 = (data) => { diff --git a/app/soapbox/reducers/instance.js b/app/soapbox/reducers/instance.js index f2fc6b5ca..3bcd1c4ba 100644 --- a/app/soapbox/reducers/instance.js +++ b/app/soapbox/reducers/instance.js @@ -2,6 +2,7 @@ import { INSTANCE_FETCH_SUCCESS, NODEINFO_FETCH_SUCCESS, } from '../actions/instance'; +import { PRELOAD_IMPORT } from 'soapbox/actions/preload'; import { Map as ImmutableMap, fromJS } from 'immutable'; const nodeinfoToInstance = nodeinfo => { @@ -31,8 +32,15 @@ const initialState = ImmutableMap({ }), }); +const preloadImport = (state, action, path) => { + const data = action.data[path]; + return data ? initialState.mergeDeep(fromJS(data)) : state; +}; + export default function instance(state = initialState, action) { switch(action.type) { + case PRELOAD_IMPORT: + return preloadImport(state, action, '/api/v1/instance'); case INSTANCE_FETCH_SUCCESS: return initialState.mergeDeep(fromJS(action.instance)); case NODEINFO_FETCH_SUCCESS: