Repository navigation
Conversation
Editing a site scoped section (e.g. a navbar with a menu) always ended up showing the "someone else updated the content in the meantime" modal, even with a single editor. The very first save went through (both stores shared the same lock version at that point), and every subsequent save failed forever. Root cause: a site scoped section is listed in a layout store (its "slot", e.g. the header/main store) while its content lives in the global site scoped store (_site), which is the store the content services actually write to. The editor forms however submitted the lock version of the *slot* store (LockVersionConcern#source_lock_version, keyed off SectionContent#store_handle). Since site scoped writes only bump the _site store, the two versions diverge after the first save and every following save raises ActiveRecord::StaleObjectError. Fixes: 1. Forms now submit the section's own lock version (LockVersionConcern#source_lock_version): the sections content fetcher already stamps each section with the lock version of the store its content comes from — the _site store for site scoped sections. This is a no-op for regular sections (their stamped version is the one of their own store). 2. The :persisted turbo stream event now dispatches the fresh lock version of the store which was actually written (UpdateSectionService / UpdateSectionBlockService return it), so the auto-saving settings forms keep working on subsequent changes. Previously the (stale) slot store version was dispatched. 3. The preview now uses the same counter: Maglev::SectionComponent #lock_version reads the lock version stamped on the section attributes instead of the unrelated site/page *model* lock versions. As a result, the section:checkLockVersion mechanism only refreshes genuinely stale preview sections instead of always refreshing site scoped ones (the two counters could never match). Tests: - request specs: with the slot and _site stores holding different lock versions, the section and block forms of a site scoped section render the _site lock version, updating with it succeeds and dispatches the bumped version, and a stale submission is still rejected with a 409. - component spec: SectionComponent#lock_version uses the stamped attribute, including for a site scoped definition. - UpdateSectionService specs now assert the returned store (the passed store for regular sections, the site scoped one for site scoped sections).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Editing a site scoped section (e.g. a navbar with a menu) always ended up showing the "someone else updated the content in the meantime" modal, even with a single editor. The very first save went through (both stores shared the same lock version at that point), and every subsequent save failed forever.
Root cause: a site scoped section is listed in a layout store (its "slot", e.g. the header/main store) while its content lives in the global site scoped store (_site), which is the store the content services actually write to. The editor forms however submitted the lock version of the slot store (LockVersionConcern#source_lock_version, keyed off SectionContent#store_handle). Since site scoped writes only bump the _site store, the two versions diverge after the first save and every following save raises ActiveRecord::StaleObjectError.
Fixes:
Forms now submit the section's own lock version (LockVersionConcern#source_lock_version): the sections content fetcher already stamps each section with the lock version of the store its content comes from — the _site store for site scoped sections. This is a no-op for regular sections (their stamped version is the one of their own store).
The :persisted turbo stream event now dispatches the fresh lock version of the store which was actually written (UpdateSectionService / UpdateSectionBlockService return it), so the auto-saving settings forms keep working on subsequent changes. Previously the (stale) slot store version was dispatched.
The preview now uses the same counter: Maglev::SectionComponent #lock_version reads the lock version stamped on the section attributes instead of the unrelated site/page model lock versions. As a result, the section:checkLockVersion mechanism only refreshes genuinely stale preview sections instead of always refreshing site scoped ones (the two counters could never match).
Tests: