Unverified Commit e3fcabe6 authored by Josh Story's avatar Josh Story Committed by GitHub

Updates our sync property access for params and searchParams to allow value (#70570)

The reasoning is that React only reads this after having set it. As long
as we allow this to be written to we can set it to the param or
searchParam value initially.
parent e701b375
...@@ -208,7 +208,6 @@ function makeAbortingExoticParams( ...@@ -208,7 +208,6 @@ function makeAbortingExoticParams(
// React Promise extension // React Promise extension
// fallthrough // fallthrough
case 'value':
case 'status': case 'status':
// Common tested properties // Common tested properties
...@@ -284,7 +283,6 @@ function makeErroringExoticParams( ...@@ -284,7 +283,6 @@ function makeErroringExoticParams(
// React Promise extension // React Promise extension
// fallthrough // fallthrough
case 'value':
case 'status': case 'status':
// Common tested properties // Common tested properties
...@@ -394,7 +392,6 @@ function makeUntrackedExoticParams(underlyingParams: Params): Promise<Params> { ...@@ -394,7 +392,6 @@ function makeUntrackedExoticParams(underlyingParams: Params): Promise<Params> {
// React Promise extension // React Promise extension
// fallthrough // fallthrough
case 'value':
case 'status': case 'status':
// Common tested properties // Common tested properties
...@@ -450,7 +447,6 @@ function makeDynamicallyTrackedExoticParamsWithDevWarnings( ...@@ -450,7 +447,6 @@ function makeDynamicallyTrackedExoticParamsWithDevWarnings(
// React Promise extension // React Promise extension
// fallthrough // fallthrough
case 'value':
case 'status': case 'status':
// Common tested properties // Common tested properties
...@@ -483,6 +479,12 @@ function makeDynamicallyTrackedExoticParamsWithDevWarnings( ...@@ -483,6 +479,12 @@ function makeDynamicallyTrackedExoticParamsWithDevWarnings(
} }
return ReflectAdapter.get(target, prop, receiver) return ReflectAdapter.get(target, prop, receiver)
}, },
set(target, prop, value, receiver) {
if (typeof prop === 'string') {
proxiedProperties.delete(prop)
}
return ReflectAdapter.set(target, prop, value, receiver)
},
ownKeys(target) { ownKeys(target) {
warnForEnumeration(store.route, unproxiedProperties) warnForEnumeration(store.route, unproxiedProperties)
return Reflect.ownKeys(target) return Reflect.ownKeys(target)
......
...@@ -206,10 +206,6 @@ function makeAbortingExoticSearchParams( ...@@ -206,10 +206,6 @@ function makeAbortingExoticSearchParams(
case 'catch': case 'catch':
case 'finally': case 'finally':
// React Promise extension
// fallthrough
case 'value':
// Common tested properties // Common tested properties
// fallthrough // fallthrough
case 'toJSON': case 'toJSON':
...@@ -307,10 +303,6 @@ function makeErroringExoticSearchParams( ...@@ -307,10 +303,6 @@ function makeErroringExoticSearchParams(
case 'catch': case 'catch':
case 'finally': case 'finally':
// React Promise extension
// fallthrough
case 'value':
// Common tested properties // Common tested properties
// fallthrough // fallthrough
case 'toJSON': case 'toJSON':
...@@ -471,7 +463,6 @@ function makeUntrackedExoticSearchParams( ...@@ -471,7 +463,6 @@ function makeUntrackedExoticSearchParams(
// React Promise extension // React Promise extension
// fallthrough // fallthrough
case 'value':
case 'status': case 'status':
// Common tested properties // Common tested properties
...@@ -593,7 +584,6 @@ function makeDynamicallyTrackedExoticSearchParamsWithDevWarnings( ...@@ -593,7 +584,6 @@ function makeDynamicallyTrackedExoticSearchParamsWithDevWarnings(
// React Promise extension // React Promise extension
// fallthrough // fallthrough
case 'value':
case 'status': case 'status':
// Common tested properties // Common tested properties
...@@ -641,6 +631,12 @@ function makeDynamicallyTrackedExoticSearchParamsWithDevWarnings( ...@@ -641,6 +631,12 @@ function makeDynamicallyTrackedExoticSearchParamsWithDevWarnings(
} }
return ReflectAdapter.get(target, prop, receiver) return ReflectAdapter.get(target, prop, receiver)
}, },
set(target, prop, value, receiver) {
if (typeof prop === 'string') {
proxiedProperties.delete(prop)
}
return Reflect.set(target, prop, value, receiver)
},
has(target, prop) { has(target, prop) {
if (typeof prop === 'string') { if (typeof prop === 'string') {
const expression = describeHasCheckingStringProperty( const expression = describeHasCheckingStringProperty(
......
...@@ -2351,7 +2351,7 @@ describe('dynamic-io', () => { ...@@ -2351,7 +2351,7 @@ describe('dynamic-io', () => {
} }
}) })
it('should not allow param names like then, value, and status when accessing params directly in a server component', async () => { it('should not allow param names like then and status when accessing params directly in a server component', async () => {
expect(getLines('In route /params')).toEqual([]) expect(getLines('In route /params')).toEqual([])
let $ = await next.render$( let $ = await next.render$(
'/params/shadowing/foo/bar/baz/qux/sync/layout/server' '/params/shadowing/foo/bar/baz/qux/sync/layout/server'
...@@ -2363,14 +2363,16 @@ describe('dynamic-io', () => { ...@@ -2363,14 +2363,16 @@ describe('dynamic-io', () => {
expect($('#param-then').text()).toEqual( expect($('#param-then').text()).toEqual(
expect.stringContaining('native code') expect.stringContaining('native code')
) )
expect($('#param-value').text()).toBe('undefined') expect($('#param-value').text()).toBe('baz')
expect($('#param-status').text()).toBe('undefined') expect($('#param-status').text()).toBe('undefined')
expect(getLines('In route /params')).toEqual([ expect(getLines('In route /params')).toEqual([
expect.stringContaining( expect.stringContaining(
'The following properties were not copied: `then`, `value`, , and `status`.' 'The following properties were not copied: `then` and `status`.'
), ),
expect.stringContaining('accessed directly with `params.dyn`'), expect.stringContaining('accessed directly with `params.dyn`'),
expect.stringContaining('accessed directly with `params.value`'),
expect.stringContaining('accessed directly with `params.dyn`'), expect.stringContaining('accessed directly with `params.dyn`'),
expect.stringContaining('accessed directly with `params.value`'),
]) ])
} else { } else {
expect($('#layout').text()).toBe('at runtime') expect($('#layout').text()).toBe('at runtime')
...@@ -2379,7 +2381,7 @@ describe('dynamic-io', () => { ...@@ -2379,7 +2381,7 @@ describe('dynamic-io', () => {
expect($('#param-then').text()).toEqual( expect($('#param-then').text()).toEqual(
expect.stringContaining('native code') expect.stringContaining('native code')
) )
expect($('#param-value').text()).toBe('undefined') expect($('#param-value').text()).toBe('baz')
expect($('#param-status').text()).toBe('undefined') expect($('#param-status').text()).toBe('undefined')
expect(getLines('In route /params')).toEqual([]) expect(getLines('In route /params')).toEqual([])
} }
...@@ -2394,14 +2396,16 @@ describe('dynamic-io', () => { ...@@ -2394,14 +2396,16 @@ describe('dynamic-io', () => {
expect($('#param-then').text()).toEqual( expect($('#param-then').text()).toEqual(
expect.stringContaining('native code') expect.stringContaining('native code')
) )
expect($('#param-value').text()).toBe('undefined') expect($('#param-value').text()).toBe('baz')
expect($('#param-status').text()).toBe('undefined') expect($('#param-status').text()).toBe('undefined')
expect(getLines('In route /params')).toEqual([ expect(getLines('In route /params')).toEqual([
expect.stringContaining( expect.stringContaining(
'The following properties were not copied: `then`, `value`, , and `status`.' 'The following properties were not copied: `then` and `status`.'
), ),
expect.stringContaining('accessed directly with `params.dyn`'), expect.stringContaining('accessed directly with `params.dyn`'),
expect.stringContaining('accessed directly with `params.value`'),
expect.stringContaining('accessed directly with `params.dyn`'), expect.stringContaining('accessed directly with `params.dyn`'),
expect.stringContaining('accessed directly with `params.value`'),
]) ])
} else { } else {
expect($('#layout').text()).toBe('at runtime') expect($('#layout').text()).toBe('at runtime')
...@@ -2410,13 +2414,13 @@ describe('dynamic-io', () => { ...@@ -2410,13 +2414,13 @@ describe('dynamic-io', () => {
expect($('#param-then').text()).toEqual( expect($('#param-then').text()).toEqual(
expect.stringContaining('native code') expect.stringContaining('native code')
) )
expect($('#param-value').text()).toBe('undefined') expect($('#param-value').text()).toBe('baz')
expect($('#param-status').text()).toBe('undefined') expect($('#param-status').text()).toBe('undefined')
expect(getLines('In route /params')).toEqual([]) expect(getLines('In route /params')).toEqual([])
} }
}) })
it('should not allow param names like then, value, and status when accessing params directly in a client component', async () => { it('should not allow param names like then and status when accessing params directly in a client component', async () => {
expect(getLines('In route /params')).toEqual([]) expect(getLines('In route /params')).toEqual([])
let $ = await next.render$( let $ = await next.render$(
'/params/shadowing/foo/bar/baz/qux/sync/layout/client' '/params/shadowing/foo/bar/baz/qux/sync/layout/client'
...@@ -2428,14 +2432,16 @@ describe('dynamic-io', () => { ...@@ -2428,14 +2432,16 @@ describe('dynamic-io', () => {
expect($('#param-then').text()).toEqual( expect($('#param-then').text()).toEqual(
expect.stringContaining('native code') expect.stringContaining('native code')
) )
expect($('#param-value').text()).toBe('undefined') expect($('#param-value').text()).toBe('baz')
expect($('#param-status').text()).toBe('undefined') expect($('#param-status').text()).toBe('undefined')
expect(getLines('In route /params')).toEqual([ expect(getLines('In route /params')).toEqual([
expect.stringContaining( expect.stringContaining(
'The following properties were not copied: `then`, `value`, , and `status`.' 'The following properties were not copied: `then` and `status`.'
), ),
expect.stringContaining('accessed directly with `params.dyn`'), expect.stringContaining('accessed directly with `params.dyn`'),
expect.stringContaining('accessed directly with `params.value`'),
expect.stringContaining('accessed directly with `params.dyn`'), expect.stringContaining('accessed directly with `params.dyn`'),
expect.stringContaining('accessed directly with `params.value`'),
]) ])
} else { } else {
expect($('#layout').text()).toBe('at runtime') expect($('#layout').text()).toBe('at runtime')
...@@ -2444,7 +2450,7 @@ describe('dynamic-io', () => { ...@@ -2444,7 +2450,7 @@ describe('dynamic-io', () => {
expect($('#param-then').text()).toEqual( expect($('#param-then').text()).toEqual(
expect.stringContaining('native code') expect.stringContaining('native code')
) )
expect($('#param-value').text()).toBe('undefined') expect($('#param-value').text()).toBe('baz')
expect($('#param-status').text()).toBe('undefined') expect($('#param-status').text()).toBe('undefined')
expect(getLines('In route /params')).toEqual([]) expect(getLines('In route /params')).toEqual([])
} }
...@@ -2459,14 +2465,16 @@ describe('dynamic-io', () => { ...@@ -2459,14 +2465,16 @@ describe('dynamic-io', () => {
expect($('#param-then').text()).toEqual( expect($('#param-then').text()).toEqual(
expect.stringContaining('native code') expect.stringContaining('native code')
) )
expect($('#param-value').text()).toBe('undefined') expect($('#param-value').text()).toBe('baz')
expect($('#param-status').text()).toBe('undefined') expect($('#param-status').text()).toBe('undefined')
expect(getLines('In route /params')).toEqual([ expect(getLines('In route /params')).toEqual([
expect.stringContaining( expect.stringContaining(
'The following properties were not copied: `then`, `value`, , and `status`.' 'The following properties were not copied: `then` and `status`.'
), ),
expect.stringContaining('accessed directly with `params.dyn`'), expect.stringContaining('accessed directly with `params.dyn`'),
expect.stringContaining('accessed directly with `params.value`'),
expect.stringContaining('accessed directly with `params.dyn`'), expect.stringContaining('accessed directly with `params.dyn`'),
expect.stringContaining('accessed directly with `params.value`'),
]) ])
} else { } else {
expect($('#layout').text()).toBe('at runtime') expect($('#layout').text()).toBe('at runtime')
...@@ -2475,7 +2483,7 @@ describe('dynamic-io', () => { ...@@ -2475,7 +2483,7 @@ describe('dynamic-io', () => {
expect($('#param-then').text()).toEqual( expect($('#param-then').text()).toEqual(
expect.stringContaining('native code') expect.stringContaining('native code')
) )
expect($('#param-value').text()).toBe('undefined') expect($('#param-value').text()).toBe('baz')
expect($('#param-status').text()).toBe('undefined') expect($('#param-status').text()).toBe('undefined')
expect(getLines('In route /params')).toEqual([]) expect(getLines('In route /params')).toEqual([])
} }
......
...@@ -388,9 +388,10 @@ describe('dynamic-io', () => { ...@@ -388,9 +388,10 @@ describe('dynamic-io', () => {
let searchWarnings = getLines('In route /search') let searchWarnings = getLines('In route /search')
if (isNextDev) { if (isNextDev) {
expect($('#layout').text()).toBe('at runtime') expect($('#layout').text()).toBe('at runtime')
expect($('[data-value]').length).toBe(2) expect($('[data-value]').length).toBe(3)
expect($('#value-sentinel').text()).toBe('hello') expect($('#value-sentinel').text()).toBe('hello')
expect($('#value-foo').text()).toBe('foo') expect($('#value-foo').text()).toBe('foo')
expect($('#value-value').text()).toBe('baz')
expect($('#page').text()).toBe('at runtime') expect($('#page').text()).toBe('at runtime')
expect(searchWarnings).toEqual([ expect(searchWarnings).toEqual([
expect.stringContaining( expect.stringContaining(
...@@ -400,6 +401,9 @@ describe('dynamic-io', () => { ...@@ -400,6 +401,9 @@ describe('dynamic-io', () => {
'accessed directly with `searchParams.sentinel`' 'accessed directly with `searchParams.sentinel`'
), ),
expect.stringContaining('accessed directly with `searchParams.foo`'), expect.stringContaining('accessed directly with `searchParams.foo`'),
expect.stringContaining(
'accessed directly with `searchParams.value`'
),
]) ])
} else { } else {
expect(searchWarnings).toHaveLength(0) expect(searchWarnings).toHaveLength(0)
...@@ -408,9 +412,10 @@ describe('dynamic-io', () => { ...@@ -408,9 +412,10 @@ describe('dynamic-io', () => {
// This test case aborts synchronously and the later component render // This test case aborts synchronously and the later component render
// triggers the outer boundary // triggers the outer boundary
expect($('main').text()).toContain('outer loading...') expect($('main').text()).toContain('outer loading...')
expect($('[data-value]').length).toBe(2) expect($('[data-value]').length).toBe(3)
expect($('#value-sentinel').text()).toBe('hello') expect($('#value-sentinel').text()).toBe('hello')
expect($('#value-foo').text()).toBe('foo') expect($('#value-foo').text()).toBe('foo')
expect($('#value-value').text()).toBe('baz')
expect($('#page').text()).toBe('at runtime') expect($('#page').text()).toBe('at runtime')
} }
...@@ -450,9 +455,10 @@ describe('dynamic-io', () => { ...@@ -450,9 +455,10 @@ describe('dynamic-io', () => {
let searchWarnings = getLines('In route /search') let searchWarnings = getLines('In route /search')
if (isNextDev) { if (isNextDev) {
expect($('#layout').text()).toBe('at runtime') expect($('#layout').text()).toBe('at runtime')
expect($('[data-value]').length).toBe(2) expect($('[data-value]').length).toBe(3)
expect($('#value-sentinel').text()).toBe('hello') expect($('#value-sentinel').text()).toBe('hello')
expect($('#value-foo').text()).toBe('foo') expect($('#value-foo').text()).toBe('foo')
expect($('#value-value').text()).toBe('baz')
expect($('#page').text()).toBe('at runtime') expect($('#page').text()).toBe('at runtime')
expect(searchWarnings).toEqual([ expect(searchWarnings).toEqual([
expect.stringContaining( expect.stringContaining(
...@@ -462,15 +468,19 @@ describe('dynamic-io', () => { ...@@ -462,15 +468,19 @@ describe('dynamic-io', () => {
'accessed directly with `searchParams.sentinel`' 'accessed directly with `searchParams.sentinel`'
), ),
expect.stringContaining('accessed directly with `searchParams.foo`'), expect.stringContaining('accessed directly with `searchParams.foo`'),
expect.stringContaining(
'accessed directly with `searchParams.value`'
),
]) ])
} else { } else {
expect(searchWarnings).toHaveLength(0) expect(searchWarnings).toHaveLength(0)
expect($('#layout').text()).toBe('at buildtime') expect($('#layout').text()).toBe('at buildtime')
expect($('main').text()).toContain('inner loading...') expect($('main').text()).toContain('inner loading...')
expect($('main').text()).not.toContain('outer loading...') expect($('main').text()).not.toContain('outer loading...')
expect($('[data-value]').length).toBe(2) expect($('[data-value]').length).toBe(3)
expect($('#value-sentinel').text()).toBe('hello') expect($('#value-sentinel').text()).toBe('hello')
expect($('#value-foo').text()).toBe('foo') expect($('#value-foo').text()).toBe('foo')
expect($('#value-value').text()).toBe('baz')
expect($('#page').text()).toBe('at runtime') expect($('#page').text()).toBe('at runtime')
} }
...@@ -690,9 +700,10 @@ describe('dynamic-io', () => { ...@@ -690,9 +700,10 @@ describe('dynamic-io', () => {
let searchWarnings = getLines('In route /search') let searchWarnings = getLines('In route /search')
if (isNextDev) { if (isNextDev) {
expect($('#layout').text()).toBe('at runtime') expect($('#layout').text()).toBe('at runtime')
expect($('[data-value]').length).toBe(2) expect($('[data-value]').length).toBe(3)
expect($('#value-sentinel').text()).toBe('hello') expect($('#value-sentinel').text()).toBe('hello')
expect($('#value-foo').text()).toBe('foo') expect($('#value-foo').text()).toBe('foo')
expect($('#value-value').text()).toBe('baz')
expect($('#page').text()).toBe('at runtime') expect($('#page').text()).toBe('at runtime')
expect(searchWarnings).toEqual([ expect(searchWarnings).toEqual([
expect.stringContaining( expect.stringContaining(
...@@ -702,13 +713,17 @@ describe('dynamic-io', () => { ...@@ -702,13 +713,17 @@ describe('dynamic-io', () => {
'accessed directly with `searchParams.sentinel`' 'accessed directly with `searchParams.sentinel`'
), ),
expect.stringContaining('accessed directly with `searchParams.foo`'), expect.stringContaining('accessed directly with `searchParams.foo`'),
expect.stringContaining(
'accessed directly with `searchParams.value`'
),
]) ])
} else { } else {
expect(searchWarnings).toHaveLength(0) expect(searchWarnings).toHaveLength(0)
expect($('#layout').text()).toBe('at runtime') expect($('#layout').text()).toBe('at runtime')
expect($('[data-value]').length).toBe(2) expect($('[data-value]').length).toBe(3)
expect($('#value-sentinel').text()).toBe('hello') expect($('#value-sentinel').text()).toBe('hello')
expect($('#value-foo').text()).toBe('foo') expect($('#value-foo').text()).toBe('foo')
expect($('#value-value').text()).toBe('baz')
expect($('#page').text()).toBe('at runtime') expect($('#page').text()).toBe('at runtime')
} }
...@@ -748,9 +763,10 @@ describe('dynamic-io', () => { ...@@ -748,9 +763,10 @@ describe('dynamic-io', () => {
let searchWarnings = getLines('In route /search') let searchWarnings = getLines('In route /search')
if (isNextDev) { if (isNextDev) {
expect($('#layout').text()).toBe('at runtime') expect($('#layout').text()).toBe('at runtime')
expect($('[data-value]').length).toBe(2) expect($('[data-value]').length).toBe(3)
expect($('#value-sentinel').text()).toBe('hello') expect($('#value-sentinel').text()).toBe('hello')
expect($('#value-foo').text()).toBe('foo') expect($('#value-foo').text()).toBe('foo')
expect($('#value-value').text()).toBe('baz')
expect($('#page').text()).toBe('at runtime') expect($('#page').text()).toBe('at runtime')
expect(searchWarnings).toEqual([ expect(searchWarnings).toEqual([
expect.stringContaining( expect.stringContaining(
...@@ -760,13 +776,17 @@ describe('dynamic-io', () => { ...@@ -760,13 +776,17 @@ describe('dynamic-io', () => {
'accessed directly with `searchParams.sentinel`' 'accessed directly with `searchParams.sentinel`'
), ),
expect.stringContaining('accessed directly with `searchParams.foo`'), expect.stringContaining('accessed directly with `searchParams.foo`'),
expect.stringContaining(
'accessed directly with `searchParams.value`'
),
]) ])
} else { } else {
expect(searchWarnings).toHaveLength(0) expect(searchWarnings).toHaveLength(0)
expect($('#layout').text()).toBe('at runtime') expect($('#layout').text()).toBe('at runtime')
expect($('[data-value]').length).toBe(2) expect($('[data-value]').length).toBe(3)
expect($('#value-sentinel').text()).toBe('hello') expect($('#value-sentinel').text()).toBe('hello')
expect($('#value-foo').text()).toBe('foo') expect($('#value-foo').text()).toBe('foo')
expect($('#value-value').text()).toBe('baz')
expect($('#page').text()).toBe('at runtime') expect($('#page').text()).toBe('at runtime')
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment