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

Live Preview: Fix the Save button wasn't overriden correctly #95639

Merged
merged 2 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const LivePreviewNotice: FC< {
};

const LivePreviewNoticePlugin = () => {
const isReady = useSelect( ( select ) => select( 'core/editor' ).__unstableIsEditorReady() );
const siteEditorStore = useSelect( ( select ) => select( 'core/edit-site' ), [] );
const previewingTheme = usePreviewingTheme();
const { canPreviewButNeedUpgrade, upgradePlan } = useCanPreviewButNeedUpgrade( previewingTheme );
Expand All @@ -72,7 +73,7 @@ const LivePreviewNoticePlugin = () => {
if ( canPreviewButNeedUpgrade ) {
return (
<>
<LivePreviewUpgradeButton { ...{ previewingTheme, upgradePlan } } />
{ isReady && <LivePreviewUpgradeButton { ...{ previewingTheme, upgradePlan } } /> }
<LivePreviewUpgradeNotice { ...{ previewingTheme, dashboardLink } } />
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,21 @@ export const LivePreviewUpgradeButton: FC< {
} );
};

if ( canvasMode === 'view' ) {
overrideSaveButtonClick( SAVE_HUB_SAVE_BUTTON_SELECTOR );
overrideSaveButtonHover( SAVE_HUB_SAVE_BUTTON_SELECTOR );
} else if ( canvasMode === 'edit' ) {
overrideSaveButtonClick( HEADER_SAVE_BUTTON_SELECTOR );
overrideSaveButtonHover( HEADER_SAVE_BUTTON_SELECTOR );
}
// Delay it to ensure the element is visible.
const timeout = window.setTimeout( () => {
if ( canvasMode === 'view' ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, maybe we don't need the delay in view mode? I don't think it's broken. The delay itself makes it a bit confusing 🥲

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's more consistent for both view and edit mode and it's safer for any dom manipulation regardless of the order of loading.

overrideSaveButtonClick( SAVE_HUB_SAVE_BUTTON_SELECTOR );
overrideSaveButtonHover( SAVE_HUB_SAVE_BUTTON_SELECTOR );
} else if ( canvasMode === 'edit' ) {
overrideSaveButtonClick( HEADER_SAVE_BUTTON_SELECTOR );
overrideSaveButtonHover( HEADER_SAVE_BUTTON_SELECTOR );
}
}, 0 );

return () => {
resetSaveButton();
resetSaveButtonHover();
clearTimeout( timeout );
};
}, [ canvasMode, previewingTheme.id, previewingTheme.type, upgradePlan ] );

Expand Down
Loading