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: clear extra styles when hydrating/mounting element #10993

wants to merge 2 commits into
base: dev


Copy link

dsanders11 commented Jan 9, 2020

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Build-related changes
  • Other, please describe:

Does this PR introduce a breaking change? (check one)

  • Yes
  • No

If yes, please describe the impact and migration path for existing applications:

Inline styles already existing on an element which Vue is mounted on, or server-side rendered DOM, may be removed if the component does not render those styles. Developers should not rely on extra inline styles being left untouched.

The PR fulfills these requirements:

If adding a new feature, the PR's description includes:

  • A convincing reason for adding this feature (to avoid wasting your time, it's best to open a suggestion issue first and wait for approval before working on it)

Other information:

There's currently a somewhat sharp gotcha with SSR where an inline style rendered for an element on the server, but not rendered on the client, will end up stuck on the element, leading to partially broken markup.

The styles may differ between the SSR DOM and the client DOM due to practices such as using the screen size as a prop value, which causes a style to be applied on the server which is not applied on the client when loaded on mobile clients. See vuetifyjs/vuetify#10163 for a real-world example of this.

I tried to keep this PR concise and focused, but it's worth discussing potential side effects of this change. Ideally it would be scoped just to hydration to limit the surface area for side effects, but that wasn't as simple as limiting it to creation, so I opted for the simpler route for the PR.

Some users may be relying on the current behavior (perhaps without realizing it), so this would break behavior for them. However, considering the current gotcha for otherwise sane looking code, it seems to be a reasonable trade-off to potentially break a tiny amount of code to remove a hard to debug issue which can lead to messed up markup.

An argument could be made that much as the DOM structure needing to match when hydrating, perhaps styles should also be required to match, which would avoid this issue. However, it seems like a tall order to ensure all styles are rendered identically between server and client since more style-oriented information is available on the client (screen size, device capabilities, etc). So, that seems like an overly burdensome requirement to put on developers for SSR. However, if that's preferred, this PR could be turned into issuing a warning on style-mismatch instead.


This comment has been minimized.

Copy link

KaelWD commented Jan 9, 2020

Related: #7063, #7787

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.