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

fix(overlay): Do not modify body styles on injection #615

Merged
merged 1 commit into from
Dec 6, 2024

Conversation

BYK
Copy link
Member

@BYK BYK commented Dec 6, 2024

Fixes #613.

We used to add overflow: auto on injection, no matter what. This is bad for a few reasons:

  1. Our default is already the closed state, so we should not do anything on initial injection
  2. We don't store or know the original value of this style we are touching, which may cause breakage
  3. It causes hydration issues as highlighted in Remix/React hydration warning for style on body #613

This PR injects a special class into the DOM using adoptedStyleSheets API on injection and just toggles this class on open/close.

Fixes #613.

We used to add `overflow: auto` on injection, no matter what. This is bad for a few reasons:

1. Our default is already the closed state, so we should not do anything on initial injection
2. We don't store or know the original value of this style we are touching, which may cause breakage
3. It causes hydration issues as highlighted in #613

This PR injects a special class into the DOM using [adoptedStyleSheets API](https://developer.mozilla.org/en-US/docs/Web/API/Document/adoptedStyleSheets) on injection and just toggles this class on open/close.
Copy link

vercel bot commented Dec 6, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
spotlightjs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 6, 2024 10:55am

@BYK BYK requested a review from Shubhdeep12 December 6, 2024 10:54
Copy link

codecov bot commented Dec 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 31.33%. Comparing base (6240009) to head (075ea39).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #615      +/-   ##
==========================================
+ Coverage   31.32%   31.33%   +0.01%     
==========================================
  Files          92       92              
  Lines        5421     5422       +1     
  Branches       99       99              
==========================================
+ Hits         1698     1699       +1     
  Misses       3723     3723              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -217,10 +218,10 @@ export default function App({
useEffect(() => {
if (!isOpen) {
spotlightEventTarget.dispatchEvent(new CustomEvent('closed'));
document.body.style.overflow = 'auto';
Copy link
Collaborator

Choose a reason for hiding this comment

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

We just need to remove this, right?

But I think it's good to have another stylesheet layer added with classname

Copy link
Member Author

Choose a reason for hiding this comment

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

Removing wouldn't fix as we need a way of undoing our "hidden" override when a user toggles Spotlight closed

@BYK BYK merged commit 4716dde into main Dec 6, 2024
17 checks passed
@BYK BYK deleted the byk/fix/no-body-alterations branch December 6, 2024 12:53
BYK pushed a commit that referenced this pull request Dec 11, 2024
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and publish to npm
yourself or [setup this action to publish
automatically](https://github.com/changesets/action#with-publishing). If
you're not ready to do a release yet, that's fine, whenever you add more
changesets to main, this PR will be updated.


# Releases
## @spotlightjs/[email protected]

### Minor Changes

- Add Sentry SDK for monitoring
([#620](#620))

### Patch Changes

-   Fix Spotlight UI not using correct sidecar URL w/ non-default port
    ([#618](#618))

- Don't alter body styles at all
([#615](#615))

-   Make in-browser direct Sentry SDK link more graceful at the start
    ([#614](#614))

-   Updated dependencies

\[[`7ea060b832a67cf39676d7fbdbbecb02bb2830e3`](7ea060b),

[`705595349718abb1dea188efc92ab02a4268f323`](7055953),

[`76bc48618812f260b8788b83926fa36fbd9ade35`](76bc486),

[`4716ddeda0e52289b0f9bc9889ffcf957a69d1a8`](4716dde),

[`a77a8698bd892762b149b555058eb345fac2c686`](a77a869),

[`6240009c99fa4699f25325e356b32dc8849e3b92`](6240009)]:
    -   @spotlightjs/[email protected]
    -   @spotlightjs/[email protected]

## @spotlightjs/[email protected]

### Patch Changes

-   Updated dependencies

\[[`455f6966d0602af38fd0835627d11dea03b88362`](455f696),

[`4716ddeda0e52289b0f9bc9889ffcf957a69d1a8`](4716dde),

[`6240009c99fa4699f25325e356b32dc8849e3b92`](6240009),

[`f0bb9a98b4df7ce49c9fd73a093dc7b2005305b9`](f0bb9a9)]:
    -   @spotlightjs/[email protected]

## @spotlightjs/[email protected]

### Patch Changes

-   Updated dependencies

\[[`7ea060b832a67cf39676d7fbdbbecb02bb2830e3`](7ea060b),

[`705595349718abb1dea188efc92ab02a4268f323`](7055953),

[`76bc48618812f260b8788b83926fa36fbd9ade35`](76bc486),

[`4716ddeda0e52289b0f9bc9889ffcf957a69d1a8`](4716dde),

[`a77a8698bd892762b149b555058eb345fac2c686`](a77a869),

[`6240009c99fa4699f25325e356b32dc8849e3b92`](6240009)]:
    -   @spotlightjs/[email protected]
    -   @spotlightjs/[email protected]

## @spotlightjs/[email protected]

### Patch Changes

- Use a maintained version of ReactJsonViewer
([#611](#611))

- - Added a createTab helper function
([#606](#606))

- Added Trace root transaction name in Trace detail header
([#612](#612))

- Don't alter body styles at all
([#615](#615))

-   Make in-browser direct Sentry SDK link more graceful at the start
    ([#614](#614))

## @spotlightjs/[email protected]

### Patch Changes

- Fix sidecar package build, export all from dist with types
([#616](#616))

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
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.

Remix/React hydration warning for style on body
2 participants