You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs: improve hot reload, add missing features (#2261)
Updated wording for clarity and consistency in the hot reload
documentation.
---------
Signed-off-by: Kévin Dunglas <kevin@dunglas.fr>
Co-authored-by: Alexandre Daubois <2144837+alexandre-daubois@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy file name to clipboardExpand all lines: docs/hot-reload.md
+23-12Lines changed: 23 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,11 +2,11 @@
2
2
3
3
FrankenPHP includes a built-in **hot reload** feature designed to vastly improve the developer experience.
4
4
5
-

5
+

6
6
7
-
This feature provides a workflow similar to **Hot Module Replacement (HMR)**found in modern JavaScript tooling (like Vite or webpack).
8
-
Instead of manually refreshing the browser after every file change (PHP code, templates, JavaScript and CSS files...),
9
-
FrankenPHP updates the content in real-time.
7
+
This feature provides a workflow similar to **Hot Module Replacement (HMR)** in modern JavaScript tooling such as Vite or webpack.
8
+
Instead of manually refreshing the browser after every file change (PHP code, templates, JavaScript, and CSS files...),
9
+
FrankenPHP updates the page content in real-time.
10
10
11
11
Hot Reload natively works with WordPress, Laravel, Symfony, and any other PHP application or framework.
12
12
@@ -23,9 +23,10 @@ Depending on your setup, the browser will either:
23
23
To enable hot reloading, enable Mercure, then add the `hot_reload` sub-directive to the `php_server` directive in your `Caddyfile`.
24
24
25
25
> [!WARNING]
26
+
>
26
27
> This feature is intended for **development environments only**.
27
-
> Do not enable `hot_reload` in production, as watching the filesystem incurs performance overhead and exposes internal endpoints.
28
-
28
+
> Do not enable `hot_reload` in production, as this feature is not secure (exposes sensitive internal details) and slows down the application.
29
+
>
29
30
```caddyfile
30
31
localhost
31
32
@@ -41,7 +42,7 @@ php_server {
41
42
42
43
By default, FrankenPHP will watch all files in the current working directory matching this glob pattern: `./**/*.{css,env,gif,htm,html,jpg,jpeg,js,mjs,php,png,svg,twig,webp,xml,yaml,yml}`
43
44
44
-
It's possible to explicitly set the files to watch using the glob syntax:
45
+
It's possible to set the files to watch using the glob syntax explicitly:
45
46
46
47
```caddyfile
47
48
localhost
@@ -56,7 +57,7 @@ php_server {
56
57
}
57
58
```
58
59
59
-
Use the long form to specify the Mercure topic to use as well as which directories or files to watch by providing paths to the `hot_reload` option:
60
+
Use the long form of `hot_reload`to specify the Mercure topic to use, as well as which directories or files to watch:
60
61
61
62
```caddyfile
62
63
localhost
@@ -95,12 +96,22 @@ To use it, add the following to your main layout:
95
96
<?php endif ?>
96
97
```
97
98
98
-
The library will automatically subscribe to the Mercure hub, fetch the current URL in the background when a file change is detected and morph the DOM.
99
-
It is available as a[npm](https://www.npmjs.com/package/frankenphp-hot-reload) package and on [GitHub](https://github.com/dunglas/frankenphp-hot-reload).
99
+
The library will automatically subscribe to the Mercure hub, fetch the current URL in the background when a file change is detected, and morph the DOM.
100
+
It is available as an[npm](https://www.npmjs.com/package/frankenphp-hot-reload) package and on [GitHub](https://github.com/dunglas/frankenphp-hot-reload).
100
101
101
102
Alternatively, you can implement your own client-side logic by subscribing directly to the Mercure hub using the `EventSource` native JavaScript class.
102
103
103
-
### Worker Mode
104
+
### Preserving Existing DOM Nodes
105
+
106
+
In rare cases, such as when using development tools [like the Symfony web debug toolbar](https://github.com/symfony/symfony/pull/62970),
107
+
you may want to preserve specific DOM nodes.
108
+
To do so, add the `data-frankenphp-hot-reload-preserve` attribute to the relevant HTML element:
109
+
110
+
```html
111
+
<divdata-frankenphp-hot-reload-preserve><!-- My debug bar --></div>
112
+
```
113
+
114
+
## Worker Mode
104
115
105
116
If you are running your application in [Worker Mode](https://frankenphp.dev/docs/worker/), your application script remains in memory.
106
117
This means changes to your PHP code will not be reflected immediately, even if the browser reloads.
@@ -127,7 +138,7 @@ php_server {
127
138
}
128
139
```
129
140
130
-
###How it works
141
+
## How It Works
131
142
132
143
1.**Watch**: FrankenPHP monitors the filesystem for modifications using [the `e-dant/watcher` library](https://github.com/e-dant/watcher) under the hood (we contributed the Go binding).
133
144
2.**Restart (Worker Mode)**: if `watch` is enabled in the worker config, the PHP worker is restarted to load the new code.
0 commit comments