Skip to content
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

className saved but not loaded on F5 (reload) #9929

Closed
manake opened this issue Sep 15, 2018 · 1 comment · Fixed by #9995
Closed

className saved but not loaded on F5 (reload) #9929

manake opened this issue Sep 15, 2018 · 1 comment · Fixed by #9995
Labels
[Feature] Block API API that allows to express the block paradigm. [Type] Bug An existing feature does not function as intended

Comments

@manake
Copy link

manake commented Sep 15, 2018

Step 1

Create a custom block:

function x() {
	wp_register_script( 'x-script', plugins_url( 'editor.js', __FILE__ ), array( 'wp-blocks', 'wp-element', 'wp-i18n', 'wp-editor' ) );

	register_block_type( 'x/y', array(
		'editor_script' => 'x-script',
	) );
}
add_action( 'init', 'x' );
(function(){
	var el = wp.element.createElement;
	var InspectorControls = wp.editor.InspectorControls;
	var __ = wp.i18n.__;

	wp.blocks.registerBlockType('x/y', {
		title: __('X'),
		icon: 'some-icon',
		category: 'layout',
		attributes: {
			x: { type: 'string', default: 'on' },
		},
		edit: function(props){
			var attributes = props.attributes;
			var isSelected = props.isSelected;
			var setAttributes = props.setAttributes;

			var inspectorControls = isSelected && el(
				InspectorControls,
				{ key: 'inspector' },
				el(wp.components.SelectControl, {
					multiple: false,
					label: __('X'),
					value: attributes.x || '',
					onChange: function onChange(value) {
						return setAttributes({ x: value });
					},
					options: [
						{ value: 'on', label: 'On' },
						{ value: 'off', label: 'Off' },
					],
				}),
			);

			return [inspectorControls, (
				el( 'div',
					{
						className: props.className,
						style: {
							'color': 'red',
						}
					},
					'Text'
				)
			)];
		},
		save: function(props){
			return null;
		},
	});
})();

Step 2:

Create another custom block with only this difference:

save: function(props){
	return el('span');
},

Step 3:

Add these two blocks to a page and add a CSS class to both. E.g. some-class.

Step 4:

Publish the page.
Both classes are saved (correct)!

Step 5:

Hit F5.

Step 6:

className is not loaded automatically back into the input for the second block (incorrect)!

Gutenberg 3.8.0.

I reported this already. This is not resolved and has been ignored #9423.

This is a bug.

className is saved in both but it's not loaded in one after hitting F5 (reload).

If this is intended (I don't see why such strange/inconsistent behavior should be intended though) then it's not documented in what circumstances className is not going to be loaded automatically back into the right field: https://wordpress.org/gutenberg/handbook/extensibility/extending-blocks/

@manake manake changed the title className not saved className saved but not loaded on F5 (reload) Sep 15, 2018
@Soean
Copy link
Member

Soean commented Sep 15, 2018

Hey @manake
thanks for reporting this issue.
I can reproduce the behavior with the build-in dynamic blocks archives and latest-posts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Block API API that allows to express the block paradigm. [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants