fix: clear extra styles when hydrating/mounting element #10993
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What kind of change does this PR introduce? (check at least one)
Does this PR introduce a breaking change? (check one)
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:
dev
branch for v2.x (or to a previous version branch), not themaster
branchfix #xxx[,#xxx]
, where "xxx" is the issue number)If adding a new feature, the PR's description includes:
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.