Skip to content

Add Yjs type to a document before reading data when using editor.blocksToYXmlFragment(blocks) #1375

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

Closed
1 task
homanp opened this issue Jan 16, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@homanp
Copy link

homanp commented Jan 16, 2025

Describe the bug
Getting the following issue when trying to transform blocks Yjs Fragments:

Invalid access: Add Yjs type to a document before reading data.

To Reproduce
https://replit.com/t/superagent/repls/ExemplaryStarkMacroinstruction/view#index.ts

Misc

  • Node version:
  • Package manager:
  • Browser:
  • I'm a sponsor and would appreciate if you could look into this sooner than later 💖
@homanp homanp added the bug Something isn't working label Jan 16, 2025
@homanp
Copy link
Author

homanp commented Jan 16, 2025

Full implementation here:

import express, { Request, Response } from "express";
import { ServerBlockNoteEditor } from "@blocknote/server-util";
import cors from "cors";

interface MarkdownRequest {
  markdown: string;
}

const app = express();
app.use(cors());
app.use(express.json());

app.post("/", async (req: Request<{}, {}, MarkdownRequest>, res: Response) => {
  const editor = ServerBlockNoteEditor.create();
  try {
    const blocks = await editor.tryParseMarkdownToBlocks(req.body.markdown);

    const YXmlFragment = editor.blocksToYXmlFragment(blocks);
    console.log(YXmlFragment);
    res.json(blocks);
  } catch (error) {
    console.error(error);
    res.status(500).json({ error: "Failed to process markdown" });
  }
});

app.listen(3000, "0.0.0.0", () => {
  console.log("Express server initialized on port 3000");
});

@YousefED
Copy link
Collaborator

YousefED commented Mar 4, 2025

Before logging YXmlFragment, you need to add it to a Y.Doc.

Or use blocksToYDoc instead

@YousefED YousefED closed this as completed Mar 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants