Skip to content

Fixed: Scope injected CSS to the viewer - #567

Merged
ahankinson merged 3 commits into
DDMAL:developfrom
etosphere:fix/scope-injected-css
Aug 13, 2026
Merged

Fixed: Scope injected CSS to the viewer#567
ahankinson merged 3 commits into
DDMAL:developfrom
etosphere:fix/scope-injected-css

Conversation

@etosphere

@etosphere etosphere commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Problem

Diva injects its stylesheet into the page at import time, and the rules aren't scoped. They apply to the whole document instead of just the viewer. That includes a * { box-sizing } reset, :root { color-scheme }, and common class names like .modal, .modal-body, .status, .thumbs*, and .canvas-label. When Diva is embedded in another app, these collide with the host's own styles.

See #566.

Fix

Two small changes:

  1. Add a diva-scope class to the viewer's root element (src/View.elm).
  2. Scope every rule under that class at build time (scripts/minify-css.mjs). The build rewrites each selector so :root becomes .diva-scope, and everything else becomes a descendant of it. For example, .modal becomes .diva-scope .modal.

Summary by CodeRabbit

  • Style

    • Standardized viewer, modal, sidebar, toolbar, thumbnail, and collection interface styling under a consistent diva- CSS namespace.
    • Preserved existing visual appearance, responsive layouts, controls, and interactions.
  • Tests

    • Updated browser tests to use the current styling selectors while preserving existing test coverage and behaviour.

@etosphere
etosphere requested a review from ahankinson August 7, 2026 20:04
@etosphere etosphere self-assigned this Aug 7, 2026
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: b21088f1-57e7-40e6-81be-c5e385fa01b1

📥 Commits

Reviewing files that changed from the base of the PR and between 096637c and 840778e.

📒 Files selected for processing (1)
  • src/styles/app.css

📝 Walkthrough

Walkthrough

The change renames viewer CSS classes and selectors with the diva- prefix. Elm views, lazy-loaded images, stylesheets, and browser tests use the updated names. Styling, rendering logic, and test behaviour remain unchanged.

Changes

CSS namespace migration

Layer / File(s) Summary
Application and collection CSS selectors
src/styles/app.css, src/styles/collection.css
Application-wide and collection selectors use the .diva- namespace. Existing declarations and responsive behaviour remain unchanged.
Modal, sidebar, and toolbar CSS selectors
src/styles/modal.css, src/styles/sidebar.css, src/styles/toolbar.css
Modal, filter, sidebar, thumbnail, contents, and toolbar selectors use the .diva- namespace.
Modal and status view class wiring
src/View.elm, src/View/ManifestInfoModal.elm, src/View/PageViewModal.elm
Rendered modal, status, filter, required-statement, throbber, and zoom elements use the renamed classes.
Collection, sidebar, toolbar, and image class wiring
src/View/CollectionExplorer.elm, src/View/Sidebar.elm, src/View/Toolbar.elm, src/View/Helpers.elm, src/viewer-element.ts
Rendered navigation, metadata, thumbnail, toolbar, and lazy-loaded image elements use the renamed classes.
Browser-test selector updates
browser-tests/auth.spec.ts, browser-tests/public-api.spec.ts
Browser tests use the renamed sidebar, contents, thumbnail, and modal selectors.

Estimated code review effort: 2 (Simple) | ~15 minutes

Suggested reviewers: ahankinson

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main goal of preventing injected CSS from affecting the host page, which the class renaming achieves.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@scripts/minify-css.mjs`:
- Around line 28-34: Update scopeSelector so a universal selector is expanded to
match both the scope element and its descendants, preserving the existing
descendant-scoping behavior for other selectors and the root pseudo-class
handling.
- Around line 37-40: Update the minification visitor configuration in transform
to scope the diva-cube-grid keyframe name using the same Diva class scope as
scopeSelector. Preserve existing selector scoping while ensuring .throbber-cube
references the scoped animation and cannot collide with host stylesheet
keyframes.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e4ead643-70e2-4a31-b431-cd90f2cb1164

📥 Commits

Reviewing files that changed from the base of the PR and between 61ce6ce and 1aa15fc.

📒 Files selected for processing (2)
  • scripts/minify-css.mjs
  • src/View.elm

Comment thread scripts/minify-css.mjs Outdated
Comment thread scripts/minify-css.mjs Outdated
@ahankinson

Copy link
Copy Markdown
Member

Did you try just changing the selectors of the specific CSS rules, instead of coding in an override?

@etosphere

Copy link
Copy Markdown
Contributor Author

Yes, that's the alternative way. The issue is that we need to rename all the generic names (modal, modal-body, status, thumbs*, canvas-*, filter-*, metadata-*, and so on), which makes this PR long. In addition, it needs to be careful when naming new classes to avoid using other generic names.

Happy to go either way. If you prefer the rename approach, I can switch to that.

@ahankinson

Copy link
Copy Markdown
Member

Yes, I would prefer that.

The injected stylesheet used generic names like .modal, .status, .thumbs,
and .canvas-label, plus `* { box-sizing }` and `:root { color-scheme }`, which
collided with host-app styles when Diva is embedded. Prefix the generic names
with `diva-`, and anchor the two element rules to `.diva-app`. Closes DDMAL#566.
@etosphere
etosphere force-pushed the fix/scope-injected-css branch from 1aa15fc to a907f01 Compare August 11, 2026 20:55

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@browser-tests/auth.spec.ts`:
- Line 471: Update the close-action locator in the auth test to use the renamed
diva-modal-close-action selector rendered by PageViewModal, replacing the
obsolete .modal-close-action button target while preserving the existing click
and hidden-state assertions.

In `@src/styles/modal.css`:
- Around line 63-68: Rename the remaining canvas-toolbar class family to the
diva-modal-prefixed equivalent across the toolbar implementation. Update emitted
class names in Toolbar.elm, definitions in toolbar.css, and the close-action
selectors in modal.css together, including both canvas-toolbar-button and
canvas-toolbar-item, so no unprefixed toolbar classes remain.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 879cdb26-a707-486c-a0be-5d44273a59d4

📥 Commits

Reviewing files that changed from the base of the PR and between 1aa15fc and a907f01.

📒 Files selected for processing (12)
  • browser-tests/auth.spec.ts
  • src/View.elm
  • src/View/CollectionExplorer.elm
  • src/View/ManifestInfoModal.elm
  • src/View/PageViewModal.elm
  • src/View/Sidebar.elm
  • src/View/Toolbar.elm
  • src/styles/app.css
  • src/styles/modal.css
  • src/styles/sidebar.css
  • src/styles/toolbar.css
  • src/viewer-element.ts

Comment thread browser-tests/auth.spec.ts Outdated
Comment thread src/styles/modal.css Outdated
Comment on lines +63 to +68
.diva-modal-actions {
display: flex;
gap: 8px;
}

.modal-close-action .canvas-toolbar-button {
.diva-modal-close-action .canvas-toolbar-button {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

Rename the remaining canvas-toolbar-* classes.

The modal selectors are prefixed, but the close-action rules still target .canvas-toolbar-button and .canvas-toolbar-item. src/View/Toolbar.elm and src/styles/toolbar.css still emit and define these unprefixed classes. They remain global and can collide with host-page styles. Rename the full toolbar class family and update all producers and selectors together.

Proposed selector direction
- .diva-modal-close-action .canvas-toolbar-button
+ .diva-modal-close-action .diva-canvas-toolbar-button

- .diva-modal-close-action .canvas-toolbar-item
+ .diva-modal-close-action .diva-canvas-toolbar-item

Also applies to: 80-85

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/styles/modal.css` around lines 63 - 68, Rename the remaining
canvas-toolbar class family to the diva-modal-prefixed equivalent across the
toolbar implementation. Update emitted class names in Toolbar.elm, definitions
in toolbar.css, and the close-action selectors in modal.css together, including
both canvas-toolbar-button and canvas-toolbar-item, so no unprefixed toolbar
classes remain.

@etosphere

Copy link
Copy Markdown
Contributor Author

CodeRabbit flagged that .canvas-toolbar-* is still unprefixed. Same goes for other classes such as .collection-* and .sidebar-*. Do you prefer prefixing all classes so everything starts with diva-, or only generic names?

@ahankinson

Copy link
Copy Markdown
Member

Let’s do everything. Fewer possibilities for conflicts in the future.

@ahankinson

Copy link
Copy Markdown
Member

I'll wait until you to the other prefixing before reviewing / testing.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/View/Sidebar.elm (1)

658-664: 🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

Complete the diva- namespace migration for modifier classes.

The reviewed files prefix the primary class names, but the CSS and Elm contract still uses generic is-* modifiers. Host-page CSS can match these tokens on viewer elements. Rename each modifier in both the emitters and selectors before merging.

  • src/View/Sidebar.elm#L658-L664: Rename panel modifiers and apply the same change at Lines 33-36, 327-340, 471-475, 619-622, 734-737, 751-756, 803-807, and 844-847.
  • src/View/Helpers.elm#L35-L39: Rename is-disabled and is-fullscreen.
  • src/styles/app.css#L197-L209: Rename .is-hidden and .is-fullscreen.
  • src/styles/collection.css#L55-L66: Rename .is-active and .is-scroll.
  • src/styles/sidebar.css#L15-L21: Rename the remaining sidebar and contents is-* selectors at Lines 41-44, 62-63, 81-85, 95-157, 167-171, and 231-257.
  • src/styles/toolbar.css#L26-L29: Rename is-right, is-fullscreen, and is-disabled, including the related selectors at Lines 84-108 and 145-152.

As per the PR objective, all CSS classes must use the diva- prefix.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/View/Sidebar.elm` around lines 658 - 664, Complete the diva- namespace
migration by renaming every listed is-* modifier emitted by src/View/Sidebar.elm
and src/View/Helpers.elm, and update all corresponding selectors in
src/styles/app.css, src/styles/collection.css, src/styles/sidebar.css, and
src/styles/toolbar.css, including the specified related ranges. Keep emitter and
selector names consistent, ensuring every CSS class uses the diva- prefix.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/View/Sidebar.elm`:
- Around line 658-664: Complete the diva- namespace migration by renaming every
listed is-* modifier emitted by src/View/Sidebar.elm and src/View/Helpers.elm,
and update all corresponding selectors in src/styles/app.css,
src/styles/collection.css, src/styles/sidebar.css, and src/styles/toolbar.css,
including the specified related ranges. Keep emitter and selector names
consistent, ensuring every CSS class uses the diva- prefix.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 1d59b32e-a0a4-42f0-bdf6-e7090b5a6747

📥 Commits

Reviewing files that changed from the base of the PR and between a907f01 and 096637c.

📒 Files selected for processing (11)
  • browser-tests/auth.spec.ts
  • browser-tests/public-api.spec.ts
  • src/View/CollectionExplorer.elm
  • src/View/Helpers.elm
  • src/View/Sidebar.elm
  • src/View/Toolbar.elm
  • src/styles/app.css
  • src/styles/collection.css
  • src/styles/modal.css
  • src/styles/sidebar.css
  • src/styles/toolbar.css
🚧 Files skipped from review as they are similar to previous changes (4)
  • browser-tests/auth.spec.ts
  • src/View/CollectionExplorer.elm
  • src/View/Toolbar.elm
  • src/styles/modal.css

@ahankinson
ahankinson merged commit 769e253 into DDMAL:develop Aug 13, 2026
1 of 2 checks passed
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