Skip to content

Commit

Permalink
Updates our sync property access for params and searchParams to allow…
Browse files Browse the repository at this point in the history
… value

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.
  • Loading branch information
gnoff committed Sep 27, 2024
1 parent 58209bd commit 27b3324
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
4 changes: 0 additions & 4 deletions packages/next/src/server/request/params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ function makeAbortingExoticParams(

// React Promise extension
// fallthrough
case 'value':
case 'status':

// Common tested properties
Expand Down Expand Up @@ -284,7 +283,6 @@ function makeErroringExoticParams(

// React Promise extension
// fallthrough
case 'value':
case 'status':

// Common tested properties
Expand Down Expand Up @@ -394,7 +392,6 @@ function makeUntrackedExoticParams(underlyingParams: Params): Promise<Params> {

// React Promise extension
// fallthrough
case 'value':
case 'status':

// Common tested properties
Expand Down Expand Up @@ -450,7 +447,6 @@ function makeDynamicallyTrackedExoticParamsWithDevWarnings(

// React Promise extension
// fallthrough
case 'value':
case 'status':

// Common tested properties
Expand Down
10 changes: 0 additions & 10 deletions packages/next/src/server/request/search-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,6 @@ function makeAbortingExoticSearchParams(
case 'catch':
case 'finally':

// React Promise extension
// fallthrough
case 'value':

// Common tested properties
// fallthrough
case 'toJSON':
Expand Down Expand Up @@ -307,10 +303,6 @@ function makeErroringExoticSearchParams(
case 'catch':
case 'finally':

// React Promise extension
// fallthrough
case 'value':

// Common tested properties
// fallthrough
case 'toJSON':
Expand Down Expand Up @@ -471,7 +463,6 @@ function makeUntrackedExoticSearchParams(

// React Promise extension
// fallthrough
case 'value':
case 'status':

// Common tested properties
Expand Down Expand Up @@ -593,7 +584,6 @@ function makeDynamicallyTrackedExoticSearchParamsWithDevWarnings(

// React Promise extension
// fallthrough
case 'value':
case 'status':

// Common tested properties
Expand Down
18 changes: 14 additions & 4 deletions test/e2e/app-dir/dynamic-io/dynamic-io.search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -690,9 +690,10 @@ describe('dynamic-io', () => {
let searchWarnings = getLines('In route /search')
if (isNextDev) {
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-foo').text()).toBe('foo')
expect($('#value-value').text()).toBe('baz')
expect($('#page').text()).toBe('at runtime')
expect(searchWarnings).toEqual([
expect.stringContaining(
Expand All @@ -702,13 +703,17 @@ describe('dynamic-io', () => {
'accessed directly with `searchParams.sentinel`'
),
expect.stringContaining('accessed directly with `searchParams.foo`'),
expect.stringContaining(
'accessed directly with `searchParams.value`'
),
])
} else {
expect(searchWarnings).toHaveLength(0)
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-foo').text()).toBe('foo')
expect($('#value-value').text()).toBe('baz')
expect($('#page').text()).toBe('at runtime')
}

Expand Down Expand Up @@ -748,9 +753,10 @@ describe('dynamic-io', () => {
let searchWarnings = getLines('In route /search')
if (isNextDev) {
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-foo').text()).toBe('foo')
expect($('#value-value').text()).toBe('baz')
expect($('#page').text()).toBe('at runtime')
expect(searchWarnings).toEqual([
expect.stringContaining(
Expand All @@ -760,13 +766,17 @@ describe('dynamic-io', () => {
'accessed directly with `searchParams.sentinel`'
),
expect.stringContaining('accessed directly with `searchParams.foo`'),
expect.stringContaining(
'accessed directly with `searchParams.value`'
),
])
} else {
expect(searchWarnings).toHaveLength(0)
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-foo').text()).toBe('foo')
expect($('#value-value').text()).toBe('baz')
expect($('#page').text()).toBe('at runtime')
}

Expand Down

0 comments on commit 27b3324

Please sign in to comment.