Skip to content

Commit a810633

Browse files
committed
wip
1 parent 9bb34db commit a810633

File tree

4 files changed

+58
-12
lines changed

4 files changed

+58
-12
lines changed

packages/signals/signals/src/core/emitter/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const logSignal = (signal: Signal) => {
1111
'New signal:',
1212
signal.type,
1313
signal.data,
14-
signal.type === 'interaction'
14+
signal.type === 'interaction' && signal.data.eventType === 'change'
1515
? {
1616
value: signal.data.target.value,
1717
changedAttribute: signal.data.target.changedAttribute,

packages/signals/signals/src/core/signal-generators/dom-gen/dom-gen.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ export class OnChangeGenerator implements SignalGenerator {
272272
changedValue: ev.newValue,
273273
changedAttribute: ev.attributeName,
274274
},
275-
listener: 'mutation-observer',
275+
listener: 'mutation',
276276
})
277277
)
278278
})
@@ -294,7 +294,7 @@ export class OnChangeGenerator implements SignalGenerator {
294294
changedValue: el.value,
295295
changedAttribute: 'value',
296296
},
297-
listener: 'on-change',
297+
listener: 'onchange',
298298
})
299299
)
300300
}, 300)

packages/signals/signals/src/core/signal-generators/network-gen/__tests__/network-generator.test.ts

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ describe(NetworkGenerator, () => {
283283
unregister()
284284
})
285285

286-
it('emits signals for same domain if networkSignalsAllowSameDomain = false', async () => {
286+
it('will not emit signals for same domain if networkSignalsAllowSameDomain = false', async () => {
287287
const mockEmitter = { emit: jest.fn() }
288288
const networkGenerator = new TestNetworkGenerator({
289289
networkSignalsAllowList: ['foo.com'],
@@ -301,7 +301,10 @@ describe(NetworkGenerator, () => {
301301
})
302302

303303
await sleep(100)
304-
expect(mockEmitter.emit.mock.calls.length).toBe(0)
304+
let requests = mockEmitter.emit.mock.calls.filter(
305+
(c) => c[0].data.action === 'request'
306+
)
307+
expect(requests.length).toBe(0)
305308

306309
await window.fetch(`http://foo.com/test`, {
307310
method: 'POST',
@@ -310,7 +313,10 @@ describe(NetworkGenerator, () => {
310313
})
311314

312315
await sleep(100)
313-
expect(mockEmitter.emit.mock.calls.length).toBe(2)
316+
requests = mockEmitter.emit.mock.calls.filter(
317+
(c) => c[0].data.action === 'request'
318+
)
319+
expect(requests.length).toBe(1)
314320

315321
unregister()
316322
})
@@ -336,6 +342,36 @@ describe(NetworkGenerator, () => {
336342
unregister()
337343
})
338344

345+
it('allows an explicit disallow list to override same-domain signals', async () => {
346+
const mockEmitter = { emit: jest.fn() }
347+
const networkGenerator = new TestNetworkGenerator({
348+
networkSignalsDisallowList: ['/foo'],
349+
})
350+
const unregister = networkGenerator.register(
351+
mockEmitter as unknown as SignalEmitter
352+
)
353+
354+
await window.fetch(`/test/foo`, {
355+
method: 'POST',
356+
headers: { 'content-type': 'application/json' },
357+
body: JSON.stringify({ key: 'value' }),
358+
})
359+
360+
await window.fetch(`/test/bar`, {
361+
method: 'POST',
362+
headers: { 'content-type': 'application/json' },
363+
body: JSON.stringify({ key: 'value' }),
364+
})
365+
366+
await sleep(100)
367+
const requests = mockEmitter.emit.mock.calls
368+
.filter((c) => c[0].data.action === 'request')
369+
.flatMap((c) => c[0].data.url)
370+
expect(requests.length).toBe(1)
371+
expect(requests[0]).toBe('http://localhost/test/bar')
372+
unregister()
373+
})
374+
339375
it('always disallows segment api network signals', async () => {
340376
const mockEmitter = { emit: jest.fn() }
341377
const networkGenerator = new TestNetworkGenerator({

packages/signals/signals/src/core/signal-generators/network-gen/network-signals-filter.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,17 @@ export class NetworkSignalsFilterList {
6565
])
6666
}
6767

68-
isAllowed(url: string): boolean {
69-
const disallowed =
70-
this.disallowed.test(url) || this.disallowedDefaults.test(url)
71-
const allowed = this.allowed.test(url)
68+
isExplicitlyDisallowed(url: string): boolean {
69+
return this.disallowed.test(url) || this.disallowedDefaults.test(url)
70+
}
71+
72+
isExplicityAllowed(url: string): boolean {
73+
return this.allowed.test(url)
74+
}
75+
76+
test(url: string): boolean {
77+
const disallowed = this.isExplicitlyDisallowed(url)
78+
const allowed = this.isExplicityAllowed(url)
7279
return allowed && !disallowed
7380
}
7481

@@ -93,9 +100,12 @@ export class NetworkSignalsFilter {
93100
const { networkSignalsFilterList, networkSignalsAllowSameDomain } =
94101
this.settings
95102

96-
const passesNetworkFilter = networkSignalsFilterList.isAllowed(url)
103+
const passesNetworkFilter = networkSignalsFilterList.test(url)
97104
const allowedBecauseSameDomain =
98-
networkSignalsAllowSameDomain && isSameDomain(url)
105+
networkSignalsAllowSameDomain &&
106+
isSameDomain(url) &&
107+
!networkSignalsFilterList.isExplicitlyDisallowed(url)
108+
99109
const allowed = passesNetworkFilter || allowedBecauseSameDomain
100110
return allowed
101111
}

0 commit comments

Comments
 (0)