-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Fix: Footnotes content not being pasted properly #70579
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
base: trunk
Are you sure you want to change the base?
Fix: Footnotes content not being pasted properly #70579
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @stacimc, @jfagreg, @sunilw. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Converting to draft as there is an issue with e2e, trying to fix |
I don't think syncing with attributes is the proper way to resolve the problem. Why?
|
@Mamaduka Got it, I will check the Original PR for the details. 👍🏻 |
I Checked the prs and the decision make sense on why post meta was used.
I am only using attributes to show what meta has. ![]() tested here and with another post with footnotes it does render data from meta.
This is the current issue that I am facing right now but not because of Effect. Is there a way to possible store the content on the block's template without adding it to the undo/redo stack? flowchart TD
A[fetch meta] --> B[initial render update useEffect]
B --> C[add metadata to attributes]
D[onChange] --> E[updateMeta new footnotes]
D --> F[setAttributes new footnotes]
Right now this is the best way I can think of. cc: @Mamaduka |
There can be cases when attributes aren't synced with meta, while race is still possible. That would qualify as a bug. There are always workarounds to fix Effects, but those escape hatches should be the last resort and not something we reach out to immediately, IMO. I pinged folks who worked on the Footnotes feature. Let's wait for their feedback. |
Let's not sync to attributes. Instead, maybe try adding a copy handler that fetches the meta and sets data transfer? |
Oh, and when you use data transfer, I'd suggest only adding the footnotes to the |
I tried implementing copy handler for footnotes and was able to add it. but when using list view to select all and copy, the list view's use-clipboard-handler uses both html and plain text to copy the content , due to which the footnotes data copied in text/html gets overridden. As footnotes also doesn't have a raw transform, making this a bit complex. So can we store metadata of a post to a new and use this to update metadata for new/current post when updating meta related blocks like footnotes. Copy handler const blockRef = useRef();
useEffect( () => {
if ( ! blockRef.current ) return;
const handleCopy = ( event ) => {
console.log( 'copied' );
const currentFootnotes = meta?.footnotes;
if ( ! currentFootnotes ) return;
const parsed = JSON.parse( currentFootnotes );
let html = '<ol>';
parsed.forEach( ( { id, content } ) => {
html += `<li id="${ id }">`;
html += `<span role="textbox" aria-multiline="true" id="${ id }" contenteditable="true" class="block-editor-rich-text__editable rich-text" style="white-space: pre-wrap; min-width: 1px;">${ content }</span> `;
html += `<a href="#${ id }-link">↩︎</a>`;
html += `</li>`;
} );
html += '</ol>';
event.clipboardData.setData(
'gutenberg/meta',
JSON.stringify( {
...meta,
footnotes: currentFootnotes,
} )
);
console.log( {
b: event.clipboardData.getData( 'gutenberg/meta' ),
} );
};
document.addEventListener( 'copy', handleCopy );
return () => {
document.removeEventListener( 'copy', handleCopy );
};
}, [ meta, blockRef ] ); Updated Clipboard handler (paste part)write flow's clipboard handler blocks = pasteHandler( {
HTML: html,
plainText,
mode: isFullySelected ? 'BLOCKS' : 'AUTO',
canUserUseUnfilteredHTML,
} );
console.log( { blocks } );
if (
Array.isArray( blocks ) &&
blocks.some( ( x ) => x.name === 'core/footnotes' )
) {
const { footnotes } = JSON.parse( meta );
console.log( { footnotes } );
if ( footnotes ) {
const meta = select( 'core/editor' ).getEditedPostAttribute( 'meta' );
setTimeout(
() =>
dispatch( 'core/editor' ).editPost( {
meta: {
...meta,
footnotes,
},
} ),
0
);
}
} |
Test ReportDescription❌This report can't validate that the indicated patch works as expected. Patch tested: https://patch-diff.githubusercontent.com/raw/WordPress/gutenberg/pull/70579.diff Environment
Testing Instructions
Actual Results
Additional Notes
Supplemental ArtifactsScreencast https://f003.backblazeb2.com/file/wordpress-videos/wp-videos/2025/07/gb57958.mp4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs changes or more testing info
@SirLouen Right now, this PR is on hold because the suggestions mentioned by ellatrix needs raw transformation support in footnotes block to convert the html version of footnotes into footnotes block this support is added indirectly in In this PR while adding support for footnotes markdown I am waiting for that PR to be merged so that we can start the progress here again. |
Good to know, I was about to test that, but I happened to find this first 👍 |
Got it! Please note that , that PR depends on this as classes property in transforms is kinda broken ( can be seen in the failed action ) ( the linked issue on that PR has details on how to reproduce it but simple version would be to just add classes: ['*'] to list block transforms) PS: I found that bug earlier on a project I was working on, which later happened again when i started working solution for footnotes markdown support |
Yes |
What?
Closes #57958
Why?
Currently footnotes are stored as
<!-- wp:footnotes />
and the content is saved as metadata.Due to this, copy pasting footnotes doesn't copy the content as it is not available.
How?
This PR aims to solve this by adding an attribute
footnotes
which is an array. This attribute is synced with themeta.footnotes
to ensure that it is compatible with older footnotes versions.This attributes allows the copied footnotes blocks to have the content available hence it will be able to render it.
Testing Instructions
3 vertical dots
)Testing Instructions for Keyboard
Screenshots or screencast
Before
Screen.Recording.2025-07-01.at.3.52.39.PM.mov
After
Screen.Recording.2025-07-01.at.3.15.26.PM.mov