Gutenberg dynamic block render_callback gives null for $post

I recently had the same issue. The workaround I used was to save the current post id as an attribute of the block:

const currentPostId = useSelect( ( select ) => {
    return select( 'core/editor' ).getCurrentPostId();
}, [] );

useEffect( () => {
    if ( currentPostId && currentPostId !== postId ) {
        setAttributes( { postId: currentPostId } );
    }
}, [ currentPostId ] );

tech