From 27b332413e48b7329f49106a01c3d53e348a3bdf Mon Sep 17 00:00:00 2001 From: Josh Story Date: Fri, 27 Sep 2024 14:06:37 -0700 Subject: [PATCH] Updates our sync property access for params and searchParams to allow 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. --- packages/next/src/server/request/params.ts | 4 ---- .../next/src/server/request/search-params.ts | 10 ---------- .../dynamic-io/dynamic-io.search.test.ts | 18 ++++++++++++++---- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/packages/next/src/server/request/params.ts b/packages/next/src/server/request/params.ts index f09ac9448f6fb9..1fb86770941a13 100644 --- a/packages/next/src/server/request/params.ts +++ b/packages/next/src/server/request/params.ts @@ -208,7 +208,6 @@ function makeAbortingExoticParams( // React Promise extension // fallthrough - case 'value': case 'status': // Common tested properties @@ -284,7 +283,6 @@ function makeErroringExoticParams( // React Promise extension // fallthrough - case 'value': case 'status': // Common tested properties @@ -394,7 +392,6 @@ function makeUntrackedExoticParams(underlyingParams: Params): Promise { // React Promise extension // fallthrough - case 'value': case 'status': // Common tested properties @@ -450,7 +447,6 @@ function makeDynamicallyTrackedExoticParamsWithDevWarnings( // React Promise extension // fallthrough - case 'value': case 'status': // Common tested properties diff --git a/packages/next/src/server/request/search-params.ts b/packages/next/src/server/request/search-params.ts index 1168423775d6ef..f1c82e59786299 100644 --- a/packages/next/src/server/request/search-params.ts +++ b/packages/next/src/server/request/search-params.ts @@ -206,10 +206,6 @@ function makeAbortingExoticSearchParams( case 'catch': case 'finally': - // React Promise extension - // fallthrough - case 'value': - // Common tested properties // fallthrough case 'toJSON': @@ -307,10 +303,6 @@ function makeErroringExoticSearchParams( case 'catch': case 'finally': - // React Promise extension - // fallthrough - case 'value': - // Common tested properties // fallthrough case 'toJSON': @@ -471,7 +463,6 @@ function makeUntrackedExoticSearchParams( // React Promise extension // fallthrough - case 'value': case 'status': // Common tested properties @@ -593,7 +584,6 @@ function makeDynamicallyTrackedExoticSearchParamsWithDevWarnings( // React Promise extension // fallthrough - case 'value': case 'status': // Common tested properties diff --git a/test/e2e/app-dir/dynamic-io/dynamic-io.search.test.ts b/test/e2e/app-dir/dynamic-io/dynamic-io.search.test.ts index f0b6c65afb6c89..4f52b7e5a028d7 100644 --- a/test/e2e/app-dir/dynamic-io/dynamic-io.search.test.ts +++ b/test/e2e/app-dir/dynamic-io/dynamic-io.search.test.ts @@ -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( @@ -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') } @@ -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( @@ -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') }