Comments (3)
Thank you for the detailed issue! This has been fixed by #6544. Keep in mind that the fix will only be available in the latest v3 beta (3.0.0-beta.37) and won't be backported to 2.0.
Target attributes have been added back to all default link converters.
I also tried (naively) to build my own implementation, but node.fields.doc.value is always the ID, never the full document, and trying to use payload.findByID within the converter causes an infinite loop that I am unable to track down.
Building an HTML converter for this was the right move, as there is no way for a default converter to know what the final URL of the internal link will be. The infinite loop from payload.findByID
could have be due to 2 issues:
- I have noticed that the default converters list was growing with every field initialization. This could have caused lag. #6544 fixed this
- In 2.0, the
payload
object was not passed through to the converter functions. Using the imported one can cause issues. In 3.0,payload
is now passed through as an argument. I have tried your provided example which usespayload.findByID
, and it works perfectly!
from payload.
Thank you @AlessioGr!
I was able to apply your filtering logic to the converters passed in to my converter to resolve the issue for the time being. Looking forward to 3.0!
import {
HTMLConverter,
LinkNode,
SerializedLinkNode,
convertLexicalNodesToHTML,
} from '@payloadcms/richtext-lexical';
import payload from 'payload';
const LinkHTMLConverter: HTMLConverter<SerializedLinkNode> = {
converter: async function ({ converters, node, parent }) {
const foundNodeTypes: string[] = [];
const filteredConverters: HTMLConverter[] = [];
for (const converter of converters) {
if (!converter.nodeTypes?.length) {
continue;
}
const newConverter: HTMLConverter = {
converter: converter.converter,
nodeTypes: [...converter.nodeTypes],
};
newConverter.nodeTypes = newConverter.nodeTypes.filter(
(nodeType) => {
if (foundNodeTypes.includes(nodeType)) {
return false;
}
foundNodeTypes.push(nodeType);
return true;
},
);
if (newConverter.nodeTypes.length) {
filteredConverters.push(newConverter);
}
}
const childrenText = await convertLexicalNodesToHTML({
converters: filteredConverters,
lexicalNodes: node.children,
parent: {
...node,
parent,
},
});
const rel: string = node.fields.newTab
? ' rel="noopener noreferrer"'
: '';
const target: string = node.fields.newTab ? ' target="_blank"' : '';
let href: string = '';
if (node.fields.linkType === 'custom') {
href = node.fields.url;
} else if (
!!node.fields.doc?.value &&
node.fields.doc?.relationTo &&
typeof node.fields.doc?.value === 'string' &&
!node.fields.doc.value.startsWith('http')
) {
const document = await payload.findByID({
id: node.fields.doc.value,
collection: node.fields.doc.relationTo,
});
href = `/${document.slug}`;
} else {
href = (node.fields.doc?.value as string) ?? '';
}
return `<a href="${href}"${target}${rel}>${childrenText}</a>`;
},
nodeTypes: [LinkNode.getType()],
};
export default LinkHTMLConverter;
from payload.
This issue has been automatically locked.
Please open a new issue if this issue persists with any additional detail.
from payload.
Related Issues (20)
- Misaligned checkboxes in List View HOT 2
- Localized group Field breaks Postgres HOT 2
- Can't use label function for document view tab HOT 2
- Uploading files from Apple Photos fails HOT 2
- Open redirect vulnerability in templates
- Array field inside localized group field is not saved HOT 4
- Data not deleting from sub-table when deleted from parent table
- plugin-form-builder should have more sensible access defaults HOT 2
- Fallback locale does not work when querying Rest API with where
- Plugin cloud storage upload file even when record is invalid
- Searching for number id: Unhandled Runtime Error (Error: invalid input syntax for type integer: "NaN") HOT 3
- Demo had no user -> Created one HOT 3
- Re: error on forgot-password route HOT 3
- Version publishing and draft permission weirdness HOT 4
- user is undefined after first user creation HOT 2
- Join field doesn't work for relationships that are nested within a tab field HOT 3
- Virtual fields do not have a list table name HOT 2
- Migration unable to run (Postgresql) HOT 3
- plugin-sentry: build fails with the Payload v2.28.0
- Write conflict error when deleting a document in afterChange hook HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from payload.