Skip to content

Commit ea55c95

Browse files
committed
add a note about side effects in created/beforeCreate
1 parent e392831 commit ea55c95

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

en/universal.md

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Because the actual rendering process needs to be deterministic, we will also be
1212

1313
Since there are no dynamic updates, of all the lifecycle hooks, only `beforeCreate` and `created` will be called during SSR. This means any code inside other lifecycle hooks such as `beforeMount` or `mounted` will only be executed on the client.
1414

15+
Another thing to note is that you should avoid code that produces global side effects in `beforeCreate` and `created`, for example setting up timers with `setInterval`. In client-side only code we may setup a timer and then tear it down in `beforeDestroy` or `destroyed`. However, because the destroy hooks will not be called during SSR, the timers will stay around forever. To avoid this, move your side-effect code into `beforeMount` or `mounted` instead.
16+
1517
## Access to Platform-Specific APIs
1618

1719
Universal code cannot assume access to platform-specific APIs, so if your code directly uses browser-only globals like `window` or `document`, they will throw errors when executed in Node.js, and vice-versa.

0 commit comments

Comments
 (0)