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

[4.x]: orderBy: 'postDate desc' leads to unexpected results in live preview #11272

Closed
wsydney76 opened this issue May 19, 2022 · 4 comments
Closed

Comments

@wsydney76
Copy link

What happened?

Description

Maybe technically not a bug, but an unexpected behavior that is somewhat hard to catch/fix:

A new entry is now created with an empty Post Date, so when postDate desc is used as orderBy in Live Preview (either by default or explicitly set), the new entry is pushed to the end of the list instead to the top as in 3.x.

(Could not find that in the upgrade docs btw.)

  • Preview target 'Original Post': entry.prev gives the oldest published entry, expected the newest
  • Preview target '... index': entry is shown on the last page, expected first position on the first page

Can be fixed by something like orderBy: expression('postDate is null desc, postDate desc'), but I think that breaks the simplicity Craft wants to provide, and should be handled in core.

Steps to reproduce

postDate is not set by hand

  1. Omit orderBy criteria or set orderBy: 'postDate desc in preview targets
  2. Check live preview

Expected behavior

The new entry is handled as 'newest' both in preview and after being published

Actual behavior

It is handled as 'oldest' in preview, and 'newest' when published

/Mel & Aylin

Craft CMS version

4.0.2

PHP version

8.1.5

Operating system and version

Windows 10

Database type and version

MySQL 5.7.14

Image driver and version

Imagick 3.7.0 (ImageMagick 7.1.0-18)

Installed plugins and versions

None

@brandonkelly
Copy link
Member

Hmm, good point! Decided the best way to fix this is to start setting placeholder Post Dates on newly-created entries, which get replaced once the author sets their own Post Date value or when the entry gets fully saved. The fix was a bit involved though, so made the change for Craft 4.1 instead of the next 4.0.x release.

@wsydney76
Copy link
Author

@brandonkelly Thanks, just took a look at 4.1.x-dev and noticed a placeholder post date is now set but not shown in the UI.

However, that looks like why the first automatic save resets the post date to NULL.

Wouldn't mind to see the post date in the form though, somehow marked as 'provisional'. It can appear on the live preview pages, and people might wonder where it came from if it's blank in the form.

brandonkelly added a commit that referenced this issue May 24, 2022
Fixes bug where the first time an unpublished draft was saved, the placeholder post date would get emptied out (#11272 (comment)).
@brandonkelly
Copy link
Member

Ah of course. Just fixed that for the next release. Thanks for testing!

@brandonkelly
Copy link
Member

Craft 4.1 is out with this change ✨

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

No branches or pull requests

2 participants