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

Can't delete document if defaultLanguages configured #34

Closed
israelroldan opened this issue Jul 20, 2023 · 1 comment · Fixed by #36
Closed

Can't delete document if defaultLanguages configured #34

israelroldan opened this issue Jul 20, 2023 · 1 comment · Fixed by #36

Comments

@israelroldan
Copy link

Thanks for making this awesome plugin available! 🎉

We just found a bug that can be reproduced in this minimal test case: https://github.dev/israelroldan/sanity-i18nplugin-tc

Description of the issue

When an internationalized field is added to a document, documents of that type can't be fully deleted.

Steps to reproduce

  1. Create a new post
  2. Try to delete it
  3. The document is deleted but immediately recreated again (same id but with all fields empty)

Expected behaviour

The document is deleted

Actual result

The document is immediately recreated empty and can't be deleted

Additional information

The root cause is the code used by the plugin to add default languages. When a document is deleted the studio hooks are re-executed and the conditions present in src/components/InternationalizedArray.tsx#108-119 are applicable so the call to handleAddLanguages(defaultLanguages) takes place, effectively adding default languages to the just deleted document, forcing its re-creation.

Disabling defaultLanguages is a workaround at the moment.

@israelroldan
Copy link
Author

I took a stab at it but it feels a bit of a chicken and egg situation as the plugin is doing the right thing (initializing defaultLanguages when the document is new) but it feels to be there should be a check of "has this document just been deleted?)

I wonder if this is more of a shortcoming of the studio (which stays on the just-deleted document URL) who is triggering the hooks on just-deleted documents.

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