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: invalid text node should not render #21093

Merged
merged 1 commit into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,13 @@
"x": 66,
"y": 556
}
},
{
"parentId": 209272202,
"wireframe": {
"id": 52129787123,
"type": "text"
}
}
],
"removes": [
Expand Down
162 changes: 162 additions & 0 deletions ee/frontend/mobile-replay/__snapshots__/transform.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,147 @@ exports[`replay/transform transform can convert images 1`] = `
]
`;

exports[`replay/transform transform can convert invalid text wireframe 1`] = `
[
{
"data": {
"height": 600,
"href": "",
"width": 300,
},
"timestamp": 1,
"type": 4,
},
{
"data": {
"initialOffset": {
"left": 0,
"top": 0,
},
"node": {
"childNodes": [
{
"id": 2,
"name": "html",
"publicId": "",
"systemId": "",
"type": 1,
},
{
"attributes": {
"data-rrweb-id": 3,
"style": "height: 100vh; width: 100vw;",
},
"childNodes": [
{
"attributes": {
"data-rrweb-id": 4,
},
"childNodes": [
{
"attributes": {
"type": "text/css",
},
"childNodes": [
{
"id": 102,
"textContent": "
body {
margin: unset;
}
input, button, select, textarea {
font: inherit;
margin: 0;
padding: 0;
border: 0;
outline: 0;
background: transparent;
padding-block: 0 !important;
}
.input:focus {
outline: none;
}
img {
border-style: none;
}
",
"type": 3,
},
],
"id": 101,
"tagName": "style",
"type": 2,
},
],
"id": 4,
"tagName": "head",
"type": 2,
},
{
"attributes": {
"data-rrweb-id": 5,
"style": "height: 100vh; width: 100vw;",
},
"childNodes": [
{
"attributes": {
"data-rrweb-id": 12345,
"style": "border-width: 4px;border-radius: 10px;border-color: #ee3ee4;border-style: solid;color: #ee3ee4;width: 100px;height: 30px;position: fixed;left: 11px;top: 12px;overflow:hidden;white-space:normal;",
},
"childNodes": [],
"id": 12345,
"tagName": "div",
"type": 2,
},
{
"attributes": {
"data-render-reason": "a fixed placeholder to contain the keyboard in the correct stacking position",
"data-rrweb-id": 9,
},
"childNodes": [],
"id": 9,
"tagName": "div",
"type": 2,
},
{
"attributes": {
"data-rrweb-id": 7,
},
"childNodes": [],
"id": 7,
"tagName": "div",
"type": 2,
},
{
"attributes": {
"data-rrweb-id": 11,
},
"childNodes": [],
"id": 11,
"tagName": "div",
"type": 2,
},
],
"id": 5,
"tagName": "body",
"type": 2,
},
],
"id": 3,
"tagName": "html",
"type": 2,
},
],
"id": 1,
"type": 0,
},
},
"timestamp": 1,
"type": 2,
},
]
`;

exports[`replay/transform transform can convert navigation bar 1`] = `
[
{
Expand Down Expand Up @@ -1453,6 +1594,20 @@ exports[`replay/transform transform incremental mutations de-duplicate the tree
},
"parentId": 52129787,
},
{
"nextId": null,
"node": {
"attributes": {
"data-rrweb-id": 52129787123,
"style": "position: fixed;left: 0px;top: 0px;overflow:hidden;white-space:normal;",
},
"childNodes": [],
"id": 52129787123,
"tagName": "div",
"type": 2,
},
"parentId": 209272202,
},
],
"attributes": [],
"removes": [
Expand Down Expand Up @@ -1689,6 +1844,13 @@ AAAAAAAAAAAAAAAAAAAAAAAAgCN/AW0xMqHnNQceAAAAAElFTkSuQmCC
"y": 556,
},
},
{
"parentId": 209272202,
"wireframe": {
"id": 52129787123,
"type": "text",
pauldambra marked this conversation as resolved.
Show resolved Hide resolved
},
},
],
"removes": [
{
Expand Down
37 changes: 37 additions & 0 deletions ee/frontend/mobile-replay/transform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,43 @@ describe('replay/transform', () => {
expect(converted).toMatchSnapshot()
})

test('can convert invalid text wireframe', () => {
const converted = posthogEEModule.mobileReplay?.transformToWeb([
{
data: {
width: 300,
height: 600,
},
timestamp: 1,
type: 4,
},
{
type: 2,
data: {
wireframes: [
{
id: 12345,
type: 'text',
x: 11,
y: 12,
width: 100,
height: 30,
style: {
color: '#ee3ee4',
borderColor: '#ee3ee4',
borderWidth: '4',
borderRadius: '10px',
},
// text property is missing
},
],
},
timestamp: 1,
},
])
expect(converted).toMatchSnapshot()
})

test('can set background image to base64 png', () => {
const converted = posthogEEModule.mobileReplay?.transformToWeb([
{
Expand Down
26 changes: 17 additions & 9 deletions ee/frontend/mobile-replay/transformer/transformers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ export function _isPositiveInteger(id: unknown): id is number {
return typeof id === 'number' && id > 0 && id % 1 === 0
}

function _isNullish(x: unknown): x is null | undefined {
return x === null || x === undefined
}

function isRemovedNodeMutation(x: addedNodeMutation | removedNodeMutation): x is removedNodeMutation {
return isObject(x) && 'id' in x
}
Expand Down Expand Up @@ -218,6 +222,17 @@ function makeTextElement(
// because we might have to style the text, we always wrap it in a div
// and apply styles to that
const id = context.idSequence.next().value

const childNodes = [...children]
if (!_isNullish(wireframe.text)) {
childNodes.unshift({
type: NodeType.Text,
textContent: wireframe.text,
// since the text node is wrapped, we assign it a synthetic id
id,
})
}

return {
result: {
type: NodeType.Element,
Expand All @@ -227,15 +242,7 @@ function makeTextElement(
'data-rrweb-id': wireframe.id,
},
id: wireframe.id,
childNodes: [
{
type: NodeType.Text,
textContent: wireframe.text,
// since the text node is wrapped, we assign it a synthetic id
id: id,
},
...children,
],
childNodes,
},
context,
}
Expand Down Expand Up @@ -983,6 +990,7 @@ function isMobileIncrementalSnapshotEvent(x: unknown): x is MobileIncrementalSna

function makeIncrementalAdd(add: MobileNodeMutation, context: ConversionContext): addedNodeMutation[] | null {
const converted = convertWireframe(add.wireframe, context)

if (!converted) {
return null
}
Expand Down
Loading