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

It fricking work #4690

Closed
wants to merge 4 commits into from
Closed

It fricking work #4690

wants to merge 4 commits into from

Conversation

louis-bompart
Copy link
Collaborator

Cleaning required but here's the two angular stone:

The first and most important is to do the "initial" replaceHistory with the router always. Without that, NextJS internal state (observable with window.history.state) is botched up and missing searchParameters, which makes everything go haywire way later down the road.

It's quite sneaky because the thing causing issue at the very end was at the very beginning (reg. execution order at least).

The caveat that comes with that is that all landing takes a double query.
It would have been the least worse evil IMO.

However, I wanted to squash it down, and so I unwrapped some new toys: The Cache.

I won't go on a spiel about caches with NextJS, it's a bit convulated. What's important to know is that essentially for what we want, we needed a Data Cache, and since Next14, well it's available (unstable, but available. It often fails in next dev, didn't manage to make it fail with next prod)

The flow is as such:

  1. User goto on /foo
  2. Server-Side-Load: nothing special this time around.
  3. On client-side-load: We create a very ephemeral cookie that contains two piece of information: the state of the SearchParameterManager after the fetchStaticState, and the parameter with which the page has been called (it will be important later)
  4. Our parameter-manager utils finally run router.replace() with the search params.
  5. Server-Side-Load: We read the cookie set on step 3 and compare it to the search params. If they "match", we recover from the cookie the parameter of the first call and use them instead of the "true" search params.
  6. We retrieve the staticState. The cache 'recognized' the param and return the cache instead of calling the platform.
  7. We invalidate the cache.
  8. We render the page as usual, with "all in sync"

Copy link

Pull Request Report

PR Title

❌ Title should follow the conventional commit spec:
<type>(optional scope): <description>

Example: feat(headless): add result-list controller

Live demo links

Bundle Size

File Old (kb) New (kb) Change (%)
case-assist 236.6 236.6 0
commerce 341.5 341.5 0
search 412.3 412.3 0
insight 401.6 401.6 0
recommendation 248.8 248.8 0
ssr 406 406 0
ssr-commerce 355.7 355.7 0

SSR Progress

Use case SSR (#) CSR (#) Progress (%)
search 39 44 89
recommendation 0 4 0
case-assist 0 6 0
insight 0 27 0
commerce 0 15 0
Detailed logs search : buildInteractiveResult
search : buildInteractiveInstantResult
search : buildInteractiveRecentResult
search : buildInteractiveCitation
search : buildGeneratedAnswer
recommendation : missing SSR support
case-assist : missing SSR support
insight : missing SSR support
commerce : missing SSR support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant