Next.js · Senior · Question 9 of 75

A Server Action is declared inside a component and uses a variable from its closure. What happens to it?

Explanation

Next.js serializes captured variables, encrypts them and embeds them in the page so the closure can be restored on invocation. Encryption protects against accidental leaks, but it's better not to keep secrets in closures. Multiple instances need a shared encryption key (NEXT_SERVER_ACTIONS_ENCRYPTION_KEY).

Further reading

Problem with a question

Next.js · Senior · question 9

Test yourself

Take the Next.js · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz