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

Possibly problematic defaults in menu templates #2138

Closed
oneiros opened this issue Jun 18, 2021 · 1 comment · Fixed by #2153
Closed

Possibly problematic defaults in menu templates #2138

oneiros opened this issue Jun 18, 2021 · 1 comment · Fixed by #2153

Comments

@oneiros
Copy link
Contributor

oneiros commented Jun 18, 2021

Sorry for not using the template. I found the following hard to get into that format.

The default templates for menu views include caching. This is the current (slim) version for a single node:

- cache node do
= content_tag :li,
class: ['nav-item', node.children.any? ? 'dropdown' : nil].compact do
= link_to_if node.url,
node.name,
@preview_mode ? 'javascript: void(0)' : node.url,
class: ['nav-link', current_page?(node.url) ? 'active' : nil].compact,
title: node.title,
target: node.external? ? '_blank' : nil,
rel: node.nofollow? ? 'nofollow' : nil
- if node.children.any?
ul.dropdown-menu
= render node.children.includes(:page, :children), as: 'node'

It uses the node itself as cache key, which seems fine at first, but upon closer inspection, there are two more things affecting the actual display of the node: An active class is added if the node is the current page and the href is replaced with javascript: void(0) in preview mode.

We stumbled upon this when in production the navigation would sometimes stop working. It was always the case when an editor opened a page in preview mode before any normal users accessed a page with the same menu. In that case the javascript: void(0) landed in the cached version ☹️

We solved this by composing a more complex cache key from [node, @page, @preview_mode]. I am not sure this is the most elegant solution, especially as this needs to be repeated in the wrapper template.

All in all this is no big deal as most sites will probably make heavy modifications to these templates anyway. Just wanted to let you know that these defaults might not be ideal.

@tvdeyen
Copy link
Member

tvdeyen commented Jun 25, 2021

Yes, this is an issue.

You are able to build your own cache key like you already described, but we should update the default templates. Would you mind to open a PR?

Thanks for bringing this into attention!

oneiros added a commit to oneiros/alchemy_cms that referenced this issue Jul 6, 2021
With the currently generated pages how menus are being displayed
depends on the (current) page and whether one is in preview mode
or not.

Thus both facts should probably go in the cache key as well.
oneiros added a commit to oneiros/alchemy_cms that referenced this issue Jul 6, 2021
With the currently generated templates the way menus are
being displayed depends on the (current) page and whether
one is in preview mode or not.

Thus both facts should probably go in the cache key as well.
oneiros added a commit to oneiros/alchemy_cms that referenced this issue Jul 9, 2021
With the currently generated templates the way menus are
being displayed depends on the (current) page and whether
one is in preview mode or not.

Thus both facts should probably go in the cache key as well.
robinboening pushed a commit to robinboening/alchemy_cms that referenced this issue Aug 13, 2021
With the currently generated templates the way menus are
being displayed depends on the (current) page and whether
one is in preview mode or not.

Thus both facts should probably go in the cache key as well.
tvdeyen added a commit that referenced this issue Sep 15, 2021
- Return only pages from current site in api [#2169](#2169) ([afdev82](https://github.com/afdev82))
- Improve cache key defaults for menus #2138 [#2160](#2160) ([oneiros](https://github.com/oneiros))
- generate picture thumbnails only for pictures with convertible format [#2130](#2130) ([afdev82](https://github.com/afdev82))
- Backport #2114 to v5.2 [#2116](#2116) ([afdev82](https://github.com/afdev82))
- Add webpacker tasks to Alchemy upgrader [#2115](#2115) ([dbwinger](https://github.com/dbwinger))
gr8bit added a commit to bichinger/alchemy_cms that referenced this issue Apr 12, 2022
….2-stable___with-active-storage

* '5.2-stable' of github.com:AlchemyCMS/alchemy_cms: (36 commits)
  Revert "Pin Ransack to below 2.4.2"
  Bump version to v5.2.7
  Autoformat page_spec.rb
  Fix copying page with descendants to a different language
  Handle copying/pasting global pages
  Bump version to v5.2.6
  Add crop_resize Dragonfly processor
  make the admin error tracker customizable
  Bump version to v5.2.5
  Adjust tinymce skin assets urls again
  Bump version to v5.2.4
  Set stampable user_class_name without root identifier
  Use relative path for tinymce font-face
  Bump version to v5.2.3
  Make sure to install correct npm package
  Bump version to v5.2.2
  Do not leak all pages for guest users in API controller
  Only return pages for current site in API
  Improve cache key defaults for menus AlchemyCMS#2138
  Bump NPM package version to 5.2.1
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants