Skip to content

Route-dependent themes cause pages to be rendered twice #4123

@ybnd

Description

@ybnd

Describe the bug

When at least one theme is configured for a particular route, the global theme is still selected first, even on pages that match that route.

This implies that at least some components on these pages will be rendered twice, and this seems like unnecessary work we should avoid.

Depending on the differences between these themes, this can also cause the style to flash briefly, which may result in layout shifts.

To Reproduce

Steps to reproduce the behavior:

  1. Configure the custom theme on a specific route by handle or uuid, and leave the dspace theme as the default
  2. Go to a page that uses the custom theme
  • You will see the style of the dspace theme for a fraction of a second
  • It will then be replaced by the style of the custom theme
  • During this time, components will start to render in the dspace theme, only to be replaced once the

Expected behavior / proposed solution

We should only render the page once we know what theme we can use.

However, this means that on such "dynamic theme pages" we'd have to retrieve all DSO ancestors in sequence, and then the theme CSS before we can render anything.
In the worst case of a deep Community/Collection hierarchy with a dynamic theme on the top-level Community this can be quite a serious delay.

This presents an opportunity to re-think how we retrieve DSO ancestors in the first place and improve performance as well.

Related work

This can cause actual problems when we assume some work is done exactly once per page: #4099
Switching to dynamic themes would be slightly quicker if we pre-fetched the CSS before JS executes, as will be possible with #3993

Metadata

Metadata

Assignees

Type

No type

Projects

Status

🏗 In Progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions