Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhance: metaをSSR HTMLに埋め込む #13436

Merged
merged 8 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/backend/src/server/web/ClientServerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ export class ClientServerService {
infoImageUrl: meta.infoImageUrl ?? 'https://xn--931a.moe/assets/info.jpg',
notFoundImageUrl: meta.notFoundImageUrl ?? 'https://xn--931a.moe/assets/not-found.jpg',
instanceUrl: this.config.url,
metaJson: JSON.stringify(meta),
};
}

Expand Down
3 changes: 3 additions & 0 deletions packages/backend/src/server/web/views/base.pug
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ html
var VERSION = "#{version}";
var CLIENT_ENTRY = "#{clientEntry.file}";

script(type='application/json' id='misskey_meta')
!= metaJson

script
include ../boot.js

Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/boot/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export async function common(createVue: () => App<Element>) {
await defaultStore.ready;
await deckStore.ready;

const fetchInstanceMetaPromise = fetchInstance();
const fetchInstanceMetaPromise = fetchInstance(true);

fetchInstanceMetaPromise.then(() => {
miLocalStorage.setItem('v', instance.version);
Expand Down
12 changes: 5 additions & 7 deletions packages/frontend/src/boot/main-boot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { alert, confirm, popup, post, toast } from '@/os.js';
import { useStream } from '@/stream.js';
import * as sound from '@/scripts/sound.js';
import { $i, signout, updateAccount } from '@/account.js';
import { fetchInstance, instance } from '@/instance.js';
import { instance } from '@/instance.js';
import { ColdDeviceStorage, defaultStore } from '@/store.js';
import { makeHotkey } from '@/scripts/hotkey.js';
import { reactionPicker } from '@/scripts/reaction-picker.js';
Expand Down Expand Up @@ -235,12 +235,10 @@ export async function mainBoot() {
}
}

fetchInstance().then(() => {
const modifiedVersionMustProminentlyOfferInAgplV3Section13Read = miLocalStorage.getItem('modifiedVersionMustProminentlyOfferInAgplV3Section13Read');
if (modifiedVersionMustProminentlyOfferInAgplV3Section13Read !== 'true' && instance.repositoryUrl !== 'https://github.com/misskey-dev/misskey') {
popup(defineAsyncComponent(() => import('@/components/MkSourceCodeAvailablePopup.vue')), {}, {}, 'closed');
}
});
const modifiedVersionMustProminentlyOfferInAgplV3Section13Read = miLocalStorage.getItem('modifiedVersionMustProminentlyOfferInAgplV3Section13Read');
if (modifiedVersionMustProminentlyOfferInAgplV3Section13Read !== 'true' && instance.repositoryUrl !== 'https://github.com/misskey-dev/misskey') {
popup(defineAsyncComponent(() => import('@/components/MkSourceCodeAvailablePopup.vue')), {}, {}, 'closed');
}
Comment on lines +238 to +241
Copy link
Contributor Author

Choose a reason for hiding this comment

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

この時点でinstanceは存在する(common bootでやってる)のでわざわざ再度fetchする必要はないため削除

Copy link
Contributor Author

Choose a reason for hiding this comment

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

この変更に関してはこのPRとは関係ないやつなので普通にdevelop突っ込んで良さそう

Copy link
Member

Choose a reason for hiding this comment

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

オフトピだけどこのダイアログ自体要らない気がするわね


if ('Notification' in window) {
// 許可を得ていなかったらリクエスト
Expand Down
25 changes: 21 additions & 4 deletions packages/frontend/src/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,27 @@ export const infoImageUrl = computed(() => instance.infoImageUrl ?? DEFAULT_INFO

export const notFoundImageUrl = computed(() => instance.notFoundImageUrl ?? DEFAULT_NOT_FOUND_IMAGE_URL);

export async function fetchInstance() {
const meta = await misskeyApi('meta', {
detail: false,
});
export async function fetchInstance(initial = false) {
const el = document.getElementById('misskey_meta');

let meta;
if (initial && el && el.textContent) {
try {
// 初回ロードはHTMLに埋め込まれたmetaを使う
meta = JSON.parse(el.textContent);
} catch (err) {
console.error(err);

// 取れなかったらAPIから取得
meta = await misskeyApi('meta', {
detail: false,
});
}
} else {
meta = await misskeyApi('meta', {
detail: false,
});
}

for (const [k, v] of Object.entries(meta)) {
instance[k] = v;
Expand Down
Loading