mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-09 11:03:43 +00:00
It seems there are some cases that [this upstream PR](https://github.com/toeverything/blocksuite/pull/4747) will cause data loss.
Because of some historical reasons, the page id could be different with its doc id.
It might be caused by subdoc migration in the following (not 100% sure if all white screen issue is caused by it) 0714c12703/packages/common/infra/src/blocksuite/index.ts (L538-L540)
In version 0.10, page id in spaces no longer has prefix "space:"
The data flow for fetching a doc's updates is:
- page id in `meta.pages` -> find `${page-id}` in `doc.spaces` -> `doc` -> `doc.guid`
if `doc` is not found in `doc.spaces`, a new doc will be created and its `doc.guid` is the same with its pageId
- because of guid logic change, the doc that previously prefixed with `space:` will not be found in `doc.spaces`
- when fetching the rows of this doc using the doc id === page id,
it will return EMPTY since there is no updates associated with the page id
The provided fix in the PR will patch the `spaces` field of the root doc so that after 0.10 the page doc can still be found in the `spaces` map. It shall apply to both of the idb & sqlite datasources.
Special thanks to @lawvs 's db file for investigation!
100 lines
2.6 KiB
TypeScript
100 lines
2.6 KiB
TypeScript
import { spawn } from 'node:child_process';
|
|
|
|
import type { ChildProcessWithoutNullStreams } from 'child_process';
|
|
import type { BuildContext } from 'esbuild';
|
|
import * as esbuild from 'esbuild';
|
|
|
|
import { config, electronDir } from './common';
|
|
|
|
// this means we don't spawn electron windows, mainly for testing
|
|
const watchMode = process.argv.includes('--watch');
|
|
|
|
/** Messages on stderr that match any of the contained patterns will be stripped from output */
|
|
const stderrFilterPatterns = [
|
|
// warning about devtools extension
|
|
// https://github.com/cawa-93/vite-electron-builder/issues/492
|
|
// https://github.com/MarshallOfSound/electron-devtools-installer/issues/143
|
|
/ExtensionLoadWarning/,
|
|
];
|
|
|
|
let spawnProcess: ChildProcessWithoutNullStreams | null = null;
|
|
|
|
function spawnOrReloadElectron() {
|
|
if (watchMode) {
|
|
return;
|
|
}
|
|
if (spawnProcess !== null) {
|
|
spawnProcess.off('exit', process.exit);
|
|
spawnProcess.kill('SIGINT');
|
|
spawnProcess = null;
|
|
}
|
|
|
|
spawnProcess = spawn('electron', ['.'], {
|
|
cwd: electronDir,
|
|
env: process.env,
|
|
});
|
|
|
|
spawnProcess.stdout.on('data', d => {
|
|
const str = d.toString().trim();
|
|
if (str) {
|
|
console.log(str);
|
|
}
|
|
});
|
|
|
|
spawnProcess.stderr.on('data', d => {
|
|
const data = d.toString().trim();
|
|
if (!data) return;
|
|
const mayIgnore = stderrFilterPatterns.some(r => r.test(data));
|
|
if (mayIgnore) return;
|
|
console.error(data);
|
|
});
|
|
|
|
// Stops the watch script when the application has quit
|
|
spawnProcess.on('exit', code => {
|
|
if (code && code !== 0) {
|
|
console.log(`Electron exited with code ${code}`);
|
|
}
|
|
});
|
|
}
|
|
|
|
const common = config();
|
|
|
|
async function watchLayers() {
|
|
let initialBuild = false;
|
|
return new Promise<BuildContext>(resolve => {
|
|
const buildContextPromise = esbuild.context({
|
|
...common,
|
|
plugins: [
|
|
...(common.plugins ?? []),
|
|
{
|
|
name: 'electron-dev:reload-app-on-layers-change',
|
|
setup(build) {
|
|
build.onEnd(() => {
|
|
if (initialBuild) {
|
|
console.log(`[layers] has changed, [re]launching electron...`);
|
|
spawnOrReloadElectron();
|
|
} else {
|
|
buildContextPromise.then(resolve);
|
|
initialBuild = true;
|
|
}
|
|
});
|
|
},
|
|
},
|
|
],
|
|
});
|
|
buildContextPromise.then(async buildContext => {
|
|
await buildContext.watch();
|
|
});
|
|
});
|
|
}
|
|
|
|
await watchLayers();
|
|
|
|
if (watchMode) {
|
|
console.log(`Watching for changes...`);
|
|
} else {
|
|
console.log('Starting electron...');
|
|
spawnOrReloadElectron();
|
|
console.log(`Electron is started, watching for changes...`);
|
|
}
|