fix: parse string style in custom attributes#367
Merged
Conversation
A layer's `style` custom attribute is stored as a raw CSS string and was applied directly to React's style prop, which expects an object. Render paths that spread props without overriding style leaked the string to the DOM and crashed SSR. Parse and merge it into the computed style instead.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
A layer's
stylecustom attribute is stored as a raw CSS string, but it was being applied directly to React'sstyleprop, which requires an object. On render paths that spread props without overridingstyle(e.g. images, inputs, iframes), the string leaked to the DOM and crashed server-side rendering withThe style prop expects a mapping from style properties to values, not a string.Changes
parseStyleStringToObject()util that parses an inline CSS string into a React style object (splits on the first colon so values with colons like URLs survive; preserves--custom-propertiesverbatim).applyCustomAttributes()util that maps HTML attribute names to their JSX equivalents and, for a stringstyle, parses and merges it into any existing computed style.customAttributesloops (element + iframe) inLayerRendererandLayerRendererPublicwith the shared helper.Test plan
style=color: red; margin-top: 10pxto a layer — element styles correctly, no console error on canvasstyle properrorstylevalue with a colon, e.g.background: url(https://x/y)— full URL preserved--accent: #f00— preserved without camelCasing