vordgi / nimpl-getters Goto Github PK
View Code? Open in Web Editor NEWImplementation of server getters and server contexts in React Server Components without switching to SSR
Home Page: https://nimpl.tech/getters
License: MIT License
Implementation of server getters and server contexts in React Server Components without switching to SSR
Home Page: https://nimpl.tech/getters
License: MIT License
Failed "Set summary" step
https://github.com/vordgi/next-impl-getters/actions/runs/8115422563/job/22183251524
Pretty sure it just needs to be added to package.json
next.js for some reason does not build the application in github workflow. Just after running the build command, next finish it immediately. Need to understand why.
Locally (Windows) all tests work correctly
Hey there @vordgi thanks for some great contributions :)
I'm just trying to learn more about these things and am aware of ye olde createServerContext
function from canary and how it was discontinued. I am also aware that many library authors that needed a server context to avoid prop drilling or pass state to faraway components (for example next-intl
) used react's cache
function to get a shared store.
They'd have us hydrate it with information within every layout and every page, since these may be rendered separately and at different times and can't share state - but the component tree inside them would have a shared state thanks to cache
. There are many blogposts on the topic created since, explaining how to make getter/setter patterns with it.
Your approach was the first time I've seen AsyncLocalStorage
used ever, and the first time I've seen it used to replace cache
. Can you please, pretty please, tell me more about the two. Why did you go with AsyncLocalStorage
over cache
, is it something that the Next.JS team is also doing, does it in any way help solve the layout/page issue etc.
thank you <3
Add info about examples and tests to readme
Update old sections
Context doesn't only work in the Provider scope
I tried each of the methods and none of them returns the base url (ex: localhost:3000
)
Is there any way to currently do this ?
I decided to collect all existing and planned next.js implementations solutions in one place.
I hope this helps improve the community and opportunities for growth.
Now the code is covered with tests that run automatically for canary next.js version, the main functionality has been added and tested. I think the package is ready for v1.0.0
Hi there,
I'm not using export const dynamic = 'force-dynamic'
as I'm trying to use static rendering where possible, I understand though that unlike getPathname()
, getSearchParams()
requires dynamic rendering as the search params can only be known at request time, not build time.
However I wondered if it's still possible to use it in draft mode, which is rendered at request time, eg.
import { getSearchParams } from 'next-impl-getters/get-search-params';
import { draftMode } from 'next/headers';
const { isEnabled } = draftMode();
if (isEnabled) {
// Page is being dynamically rendered
const token = getSearchParams({ ignoreDynamicOptionErrors: true }).get('token');
} else {
// Page is being statically rendered
}
This does work locally, but not on a preview deployment on Vercel.
Is this possible? Or am I missing something
Thanks!
Cover server contexts with tests in all aspects
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.