Skip to content

Commit

Permalink
Fixes website not loading for unlogged users (mastodon#27698)
Browse files Browse the repository at this point in the history
  • Loading branch information
renchap authored and vmstan committed Dec 14, 2023
1 parent df39522 commit d7bdda3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
24 changes: 13 additions & 11 deletions app/javascript/mastodon/reducers/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,40 +41,42 @@ const normalizeAccounts = (
return state;
};

export const accountsReducer: Reducer<typeof initialState> = (
state = initialState,
action,
) => {
const currentUserId = me;

if (!currentUserId)
function getCurrentUser() {
if (!me)
throw new Error(
'No current user (me) defined when calling `accountsReducer`',
);

return me;
}

export const accountsReducer: Reducer<typeof initialState> = (
state = initialState,
action,
) => {
if (revealAccount.match(action))
return state.setIn([action.payload.id, 'hidden'], false);
else if (importAccounts.match(action))
return normalizeAccounts(state, action.payload.accounts);
else if (followAccountSuccess.match(action))
else if (followAccountSuccess.match(action)) {
return state
.update(
action.payload.relationship.id,
(account) => account?.update('followers_count', (n) => n + 1),
)
.update(
currentUserId,
getCurrentUser(),
(account) => account?.update('following_count', (n) => n + 1),
);
else if (unfollowAccountSuccess.match(action))
} else if (unfollowAccountSuccess.match(action))
return state
.update(
action.payload.relationship.id,
(account) =>
account?.update('followers_count', (n) => Math.max(0, n - 1)),
)
.update(
currentUserId,
getCurrentUser(),
(account) =>
account?.update('following_count', (n) => Math.max(0, n - 1)),
);
Expand Down
17 changes: 17 additions & 0 deletions spec/system/unlogged_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

require 'rails_helper'

describe 'UnloggedBrowsing' do
subject { page }

before do
visit root_path
end

it 'loads the home page' do
expect(subject).to have_css('div.app-holder')

expect(subject).to have_css('div.columns-area__panels__main')
end
end

0 comments on commit d7bdda3

Please sign in to comment.