Skip to content

Block background doesn't work on Site Editor section #61187

Open

Description

In the project’s themes folder there is a banner block

Screenshot from 2024-04-29 12-05-20

banner.js file

import { InnerBlocks } from "@wordpress/block-editor"

wp.blocks.registerBlockType("ourblocktheme/banner", {
    title: "Banner",
    edit: EditComponent,
    save: SaveComponent
});

function EditComponent() {
    const useMeLater = (
        <>
            <h1 className="headline headline--large">Welcome!</h1>
            <h2 className="headline headline--medium">We think you&rsquo;ll like it
                here.</h2>
            <h3 className="headline headline--small">Why don&rsquo;t you check out
                the <strong>major</strong> you&rsquo;re interested in?</h3>
            <a href="#" className="btn btn--large btn--blue">Find Your Major</a>
        </>
    )

    return (
        <div className="page-banner">
            <div className="page-banner__bg-image"
                 style={{backgroundImage: "url('/wp-content/themes/fictional-block-theme/images/library-hero.jpg')"}}></div>
            <div className="page-banner__content container t-center c-white">
                <InnerBlocks />
            </div>
        </div>
    )
}

function SaveComponent() {
    return (
        <div className="page-banner">
            <div className="page-banner__bg-image"
                 style={{backgroundImage: "url('/wp-content/themes/fictional-block-theme/images/library-hero.jpg')"}}></div>
            <div className="page-banner__content container t-center c-white">
                <InnerBlocks.Content />
            </div>
        </div>
    )
}

Added theme CSS files for the editor pages in the functions.php file

function university_features() {
  add_theme_support('editor-styles');
  add_editor_style(array('https://fonts.googleapis.com/css?family=Roboto+Condensed:300,300i,400,400i,700,700i|Roboto:100,300,400,400i,700,700i', 'build/style-index.css', 'build/index.css'));
}

add_action("after_setup_theme", "university_features");

On style attribute as a temporary background is used this path background-image: "url('/wp-content/themes/fictional-block-theme/images/library-hero.jpg')"

banner.js -> EditComponent

<div className="page-banner">
  <div
    className="page-banner__bg-image"
    style={{
      backgroundImage:
        "url('/wp-content/themes/fictional-block-theme/images/library-hero.jpg')",
    }}
  ></div>
  <div className="page-banner__content container t-center c-white">
    <InnerBlocks />
  </div>
</div>;

If it's edited any blog post (or another post type), the background appears but on the Site Editor page the image isn’t rendered

Post Editing

Screenshot from 2024-04-29 12-25-41

Screenshot from 2024-04-29 12-29-30

Screenshot from 2024-04-29 12-32-27

image (2)

Site Editor section

Screenshot from 2024-04-29 12-34-40

Screenshot from 2024-04-29 12-37-01

Screenshot from 2024-04-29 12-38-35

Screenshot from 2024-04-29 12-40-53

Screenshot from 2024-04-29 12-43-12

image (3) (1)

What is the problem here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Needs TestingNeeds further testing to be confirmed.Needs further testing to be confirmed.[Package] Block editor/packages/block-editor/packages/block-editor[Status] StaleGives the original author opportunity to update before closing. Can be reopened as needed.Gives the original author opportunity to update before closing. Can be reopened as needed.[Type] BugAn existing feature does not function as intendedAn existing feature does not function as intended[Type] Help RequestHelp with setup, implementation, or "How do I?" questions.Help with setup, implementation, or "How do I?" questions.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions