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

Search results entry fields are not updated correctly when collection entry fields are updated across multiple languages #7203

Closed
tiagom-m opened this issue Jul 17, 2024 · 8 comments
Assignees
Labels

Comments

@tiagom-m
Copy link

tiagom-m commented Jul 17, 2024

Link to reproduction

No response

Payload Version

beta.63

Node Version

20 LTS

Next.js Version

15.0.0-canary.58

Describe the Bug

When the Search Plugin is enabled for a collection, publishing changes in multiple languages for an entry from that collection do not update the fields for all languages in the respective search entry.

When changes across languages are published for an entry, only the values for the selected language are stored in the respective search entry. The values for the other languages are not saved in that search entry.

The current beta app (version 63) was used for testing and the following changes were added to the payload.config.ts:

  • Localization was enabled for English (EN) and French (FR) languages
localization : {
    locales: ['en','fr'],
    defaultLocale: 'en',
    fallback: true
}
  • The Search Plugin was enaled for the pages collection, and a localized slug field was added
searchPlugin({
    collection: ['pages'],
    defaultPriorities: {
        pages: 10
    },
    searchOverrides: {
        fields: ({defaultFields}) => [
            ...defaultFields,
            {
                name: 'slug',
                required: false,
                type: 'text',
                localized: true
            },
        ] as Field[]
    },
    beforeSync: ({originalDoc, searchDoc}) => {
        return {
            ...searchDoc,
            slug: originalDoc.slug
        } as DocToSync
    }
})

After updating the title and slug fields for a new page for both EN and FR, several issues are visible in the search results entry when those changes are published:

  • If the EN language was the one selected when publishing the changes, only the title and slug values for EN are updated correctly. Switching to the FR language reveals that the title remains unchanged (since it's not a localized field) and the slug field appears empty (meaning that the entry slug inFR was not stored).
  • If the slug value is updated again and the FR language is selected before publishing changes, the slug field in the search result entry is updated but the slug field in EN is now empty (meaning that the entry slug in EN was not stored).
  • I think that it would also be beneficial for the title field to the possible to be localized in order to avoid confusion when changing across different languages in the same entry.

I was not able to find a lot of documentation (or a working example) on how to setup the search plugin for multiple locales were it worked properly, so maybe I might be missing some more configurations.

Reproduction Steps

  • Created a new project with the npx create-payload-app@beta command and followed the setup instructions.
  • Modified the payload.config.ts file to enable localization and the search plugin, as shown above.
  • Executed the database migration commands.
  • Created a new page with different title and slug values for the FR and EN languages and published the changes, ensuring that the EN language is the one currently active.
  • Checked the Search results collection for the search entry for the new page.
  • Confirmed that the title and slug values matched those from the page for EN, while the slug value for FR is empty. The title field also does not change between languages.
  • Updated again the slug value for the same page but ensured that the FR language was the one active when publishing the changes.
  • Checked the search result entry again. The field and slug values matched those from the page in FR, but for EN the title did not changed and the slug value was empty.

Adapters and Plugins

plugin-search

@tiagom-m tiagom-m added status: needs-triage Possible bug which hasn't been reproduced yet v3 labels Jul 17, 2024
@tiagom-m tiagom-m changed the title Search Plugin results fields are not upated correctly when entry fields are updated for multiple languages Search Plugin results entries are not updated correctly when entry fields are updated in multiple languages Jul 17, 2024
@tiagom-m tiagom-m changed the title Search Plugin results entries are not updated correctly when entry fields are updated in multiple languages Search results entries are not updated correctly when entry fields are updated in multiple languages Jul 17, 2024
@tiagom-m tiagom-m changed the title Search results entries are not updated correctly when entry fields are updated in multiple languages Search results entry fields are not updated correctly when collection entry fields are updated in multiple languages Jul 17, 2024
@tiagom-m tiagom-m changed the title Search results entry fields are not updated correctly when collection entry fields are updated in multiple languages Search results entry fields are not updated correctly when collection entry fields are updated across multiple languages Jul 17, 2024
@JarrodMFlesch
Copy link
Contributor

@tiagom-m I think I am following, but could you upload a quick screen capture of this process?

@tiagom-m
Copy link
Author

tiagom-m commented Jul 18, 2024

Maybe with these screenshots I can better explain the issue I'm having than with only a screen capture.

1. Create a new page with content for fr and en languages. The en locale is selected when the changes are published.
IMG_0946
IMG_0947
2. This is the search result entry that is created in the Search Results collection when the page changes are published. For the en locale, the values match the page values, but for the fr locale is visible that no slug value is saved and that the title and doc relationship remain the same as in the en language.
IMG_0948
IMG_0949
3. The fields of the created page are updated again and the fr locale is the one selected when these changes are published.
IMG_0950
IMG_0951
4. The search entry fields are updated. For the fr locale, the values match the updated page values, except the Doc relationship that still shows the en page title. Changing to the en locale, is visible that the title and doc relationship match the values from the fr language and the slug field is not saved.
IMG_0953
IMG_0952

I assume that the expected behaviour for the search result entry is for the fields to match the values of the page fields across all supported languages.

@JarrodMFlesch JarrodMFlesch self-assigned this Jul 19, 2024
@github-actions github-actions bot removed the status: needs-triage Possible bug which hasn't been reproduced yet label Jul 19, 2024
@JarrodMFlesch
Copy link
Contributor

I can attempt to recreate the search issue you are having.

One thing to note, when you switch between locales, it does not store your current document data. So I think you were losing it when you switched from FR to EN which made it seem like it was not saving.

If you update to the latest beta, I made a change to make this clearer and it will ask you if you want to leave without saving. Can you try that out and see if it clears up some of the initial confusion you were having?

@tiagom-m
Copy link
Author

tiagom-m commented Jul 21, 2024

I updated to the latest version the beta project and tested it again.
Since I have the Drafts functionally with autosave enabled, I don't think that the issue is related to the data not being stored in the document.

I think that the issue still persists, so in this capture I went throught the steps described in my last message to better show the issue I'm facing.

test.MOV

@JarrodMFlesch
Copy link
Contributor

@tiagom-m thank you for the screen recording, this is so helpful. I should have time to look into this today.

@JarrodMFlesch
Copy link
Contributor

So to recreate this issue:

  • create DRAFT version of es doc
  • create PUBLISHED version of en doc
  • the search collection will only have the en data

This stems from afterRead hooks only having access to the data of the requested locale. The search plugin allows you to tie into afterRead, but the doc will only have the en data. Therefore the search doc will not have access to other localized content when it creates/updates its entry.

@JarrodMFlesch
Copy link
Contributor

@tiagom-m will be fixed in next beta release

Copy link

github-actions bot commented Sep 7, 2024

This issue has been automatically locked.
Please open a new issue if this issue persists with any additional detail.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants