Skip to content

Fix: nested + i18n customPath issue #7418

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

Merged

Conversation

demshy
Copy link
Member

@demshy demshy commented Feb 26, 2025

Summary

Addressing #7389

When using nested collection combined with i18n, we encountered a bug, where instead of saving content, we would get empty commits. This did not happen when using local backend via proxy.
After inspecting exactly what happens in the backend implementation I figured out that the problem actually happens in backend.ts when it sets the newPath property as if the file was being renamed every time the customPath is set. This way the updateTree function in the API.ts goes into another mode, loops the i18n files and eventually updates the tree with existing blob IDS instead of the newly uploaded ones.
Added a condition where newPath is passed on only if it differs from the currentPath - so only in case the file is actually being moved.

Test plan

local_backend: true

backend:
  name: git-gateway
  branch: decap-debug
  squash_merges: true

display_url: https://hugo-template.netlify.app/
logo_url: /media/brand/logo.svg
media_folder: static/media/uploads
public_folder: /media/uploads

i18n:
  structure: multiple_files
  locales: [en, sl]

slug:
  encoding: ascii
  clean_accents: true

collections:
  - label: 'subfolders'
    name: 'subfolders'
    folder: 'content/subfolders'
    identifier_field: 'title'
    create: true
    i18n: true
    extension: 'md'
    meta: { path: { widget: string, label: 'Path', index_file: 'index' } }
    nested:
      depth: 10
      subfolders: true
      summary: '{{title}}'
    fields:
      - { label: 'Title', name: 'title', widget: 'string', i18n: true }

Directory structure

subfolders
└── management
    ├── index.en.md
    ├── index.sl.md
    └── nested
        └── index.en.md

When editing the nested entry using Github gateway it will no longer result in an empty commit instead of crating the index.sl.md file.

Checklist

Please add a x inside each checkbox:

A picture of a cute animal (not mandatory but encouraged)
image

@demshy demshy requested a review from a team as a code owner February 26, 2025 08:52
@martinjagodic martinjagodic merged commit 86d41d7 into decaporg:main Mar 7, 2025
9 checks passed
@martinjagodic martinjagodic deleted the fix/nested-i18n-custom-path branch March 7, 2025 08:55
dfdez added a commit to Feverup/decap-cms that referenced this pull request Jun 6, 2025
* feat(nested collections): allow non-index files (decaporg#7359)

* feat(nested collections): allow non-index files

This commit fixes decaporg#4972 to allow nested folders with additional content
beyond an index file.

Side effect: To keep the feature simple, this will now show index files
as pages within a folder in NetlifyCMS. This enables creating additional
files alongside the given index, but is a change in behavior from the
current implementation.

Co-authored-by: Eric Gade <[email protected]>

* test(e2e): adapt to new way nested collections work

 We use regexps as otherwise .contains("Sub Directory") would also match "Another Sub Directory"

---------

Co-authored-by: Andrew Dunkman <[email protected]>
Co-authored-by: Eric Gade <[email protected]>
Co-authored-by: Anze Demsar <[email protected]>

* fix(markdown): convert inline CSS from Google Docs to Markdown (decaporg#7351)

Extends the HTML to Markdown conversion to better support bold and
italic formatting from Google Docs, which generates inline styles on a
`span` element instead of strong/b/em/i type elements.

Co-authored-by: Anze Demsar <[email protected]>

* feat: visual editing (click-to-edit) (decaporg#7374)

* refactor: clean up controlRef handling

* feat: add click-to-edit

* test: update snapshots

---------

Co-authored-by: Anze Demsar <[email protected]>

* fix(widgetsFor): return widgets for variable type lists (decaporg#7296)

When using a Variable Type list widget and a custom preview component,
the `widgetsFor` helper would only return a `data` list with each of the
items in the list, not a `widgets` list, e.g.

    {"data" =>
        {"markdown" => "# Title"}
        {"type" => "block_body"}
    }
    {"widgets" => undefined} 🚫

The `widgets` list should also be supplied, particularly for nested
Markdown widgets, so a fully formatted preview can be rendered:

    {"data" =>
        {"markdown" => "# Title"}
        {"type" => "block_body"}
    }
    {"widgets" =>
        {"markdown" => Object} ✅
    }

This extends support in `widgetsFor` to detect variable type list
widgets and correctly construct the `widgets` return value.

As reported at decaporg#2307 (comment)

Co-authored-by: Anze Demsar <[email protected]>

* chore(release): publish

 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]

* fix(ObjectControl): hotfix nested object validation (decaporg#7385)

* chore(release): publish

 - [email protected]
 - [email protected]
 - [email protected]

* chore: update to upload-artifact@v4 (decaporg#7388)

* feat(nested collections) legacy mode (decaporg#7387)

* feat(nested-collections): opt-in to legacy nested folder behaviour

* style: lint

* feat(nested-collection): default subfolders to true

* test(nested-collections): keep the tests in the subfolders: false scenario

* chore(release): publish

 - [email protected]
 - [email protected]
 - [email protected]

* fix(nested-i18n): pass newPath only when customPath differs from current path (decaporg#7418)

* fix(decaporg#7371): Duplicate Localized Content When Duplicating Entries with i18n Enabled (decaporg#7372)

* chore: add i18n to EntryObject type

* fix: draftDuplicateEntry function duplicate i18n data

---------

Co-authored-by: Anze Demsar <[email protected]>

* chore(release): publish

 - [email protected]
 - [email protected]
 - [email protected]

* Update README.md, fix spelling error (decaporg#7472)

* PNW-2564 - duplicate workflow (#21)

* Merge with feature/PNW-2564_duplicate--wip

* feat: duplicate workflow wip

* feat: duplicate workflow wip

* feat: added local empty draft

* feat: added isCustomEntry to edit state with data

* feat: added function to retrieve current unpublished entries

* feat: added enty and avoid problems if empty is missing

* feat: refactor context structure and error name with integration

---------

Co-authored-by: Felix Gnass <[email protected]>
Co-authored-by: Andrew Dunkman <[email protected]>
Co-authored-by: Eric Gade <[email protected]>
Co-authored-by: Anze Demsar <[email protected]>
Co-authored-by: Dominic Cleal <[email protected]>
Co-authored-by: Anze Demsar <[email protected]>
Co-authored-by: starkovio <[email protected]>
Co-authored-by: kare-rentelligent <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants