![Create React App Officially Deprecated Amid React 19 Compatibility Issues](https://cdn.sanity.io/images/cgdhsj6q/production/04fa08cf844d798abc0e1a6391c129363cc7e2ab-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
@emergence-engineering/lexical-link-preview-plugin
Advanced tools
A link preview plugin for Lexical editor
This easy-to-use plugin for lexical editors enhances the user experience by allowing them to see the page behind the link.
The plugin takes three properties that allow you to:
The plugin applies the data to the preview box and shows you the name, the description and, if available, the image of the website. You can easily customize the preview - use the popular 'card' design, stick to the 'bookmark' style, or create your own - whichever fits better to your UI.
npm i -S lexical-link-preview-plugin
import { LinkPreviewNode, LinkPreviewPlugin } from "lexical-link-preview-plugin";
theme: {linkPreviewContainer: "linkPreviewContainer",}
You can use your custom css to style the preview, here is an example (which is the actual css used by default)
basic card structure
<BlockWithAlignableContents className={className} nodeKey={nodeKey}>
<div className={"previewBox"}>
<a href={url} target={"_blank"}>
<img className={"previewImage"} src={res.images[0]} alt={""} />
<div className={"previewText"}>
<div className={"previewTitle"}>{res.title}</div>
<div className={"previewDescription"}>{res.description}</div>
</div>
{showClosePreview && (
<div
className="closePreview"
onClick={(e) => {
e.preventDefault();
onClose();
}}
>×</div>
)}
</a>
</div>
</BlockWithAlignableContents>
Add the node to the nodes array in your config: LinkPreviewNode
nodes: [LinkPreviewNode,]
Initialize the editor with the plugin
import { LinkPreviewNode, LinkPreviewPlugin } from "lexical-link-preview-react"
const initialconfig = {
namespace: "yourEditor",
theme: {linkPreviewContainer: "linkPreviewContainer"},
onError,
nodes: [LinkPreviewNode]
}
const fetchingFunction = async (link: string) => {
const data = await fetch("/api/link-preview", {
method: "POST",
body: JSON.stringify({
link,
}),
});
const {
data: { url, title, description, images },
} = await data.json();
return { url, title, description, images };
};
const Editor = (): JSX.Element => {
return (
<LexicalComposer initialConfig={initialConfig}>
<LinkPreviewPlugin
showLink={false}
showClosePreview={false}
fetchDataForPreview={fetchingFunction}
/>
<RichTextPlugin
contentEditable={<ContentEditable />}
placeholder={placeholder}
ErrorBoundary={LexicalErrorBoundary}
/>
</LexicalComposer>
)
}
LinkPreviewPlugin
requires 3 parameters:
showLink
: takes a boolean value
showClosePreview
: takes a boolean value - if true, it returns a close button in the upper right corner to close the preview (by default you can close it with the 'delete' or 'backspace' key)
fetchDataForPreview
: (link: string) => Promise<{url: string, title: string, description: string, images: string[]}>
a function that takes a link and returns a Promise
that resolves to the link preview data, you can easily do this using next.js API routes or just using link-preview-js
library on your custom backend
import type { NextApiRequest, NextApiResponse } from "next";
import Cors from "cors";
import { getLinkPreview } from "link-preview-js";
// Initializing the cors middleware
// You can read more about the available options here: https://github.com/expressjs/cors#configuration-options
const cors = Cors({
methods: ["POST", "GET", "HEAD"],
});
// Helper method to wait for a middleware to execute before continuing
// And to throw an error when an error happens in a middleware
function runMiddleware(
req: NextApiRequest,
res: NextApiResponse,
fn: Function
) {
return new Promise((resolve, reject) => {
fn(req, res, (result: any) => {
if (result instanceof Error) {
return reject(result);
}
return resolve(result);
});
});
}
export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
// Run the middleware
await runMiddleware(req, res, cors);
const { link } = JSON.parse(req.body);
console.log({ link });
const data = await getLinkPreview(link);
// Rest of the API logic
res.json({ data });
}
this does not happen automatically, you need to handle it yourself by providing the fetchDataForPreview
callback function
link-preview-js
linkpreview.net
API endpoint to fetch your preview data from the frontendFAQs
A link preview plugin for Lexical editor
The npm package @emergence-engineering/lexical-link-preview-plugin receives a total of 2 weekly downloads. As such, @emergence-engineering/lexical-link-preview-plugin popularity was classified as not popular.
We found that @emergence-engineering/lexical-link-preview-plugin demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.