Skip to content

Commit b49189e

Browse files
dunglasalexandre-dauboisCopilot
authored
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>
1 parent 808757c commit b49189e

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

docs/hot-reload.md

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
FrankenPHP includes a built-in **hot reload** feature designed to vastly improve the developer experience.
44

5-
![Mercure](hot-reload.png)
5+
![Hot Reload](hot-reload.png)
66

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.
1010

1111
Hot Reload natively works with WordPress, Laravel, Symfony, and any other PHP application or framework.
1212

@@ -23,9 +23,10 @@ Depending on your setup, the browser will either:
2323
To enable hot reloading, enable Mercure, then add the `hot_reload` sub-directive to the `php_server` directive in your `Caddyfile`.
2424

2525
> [!WARNING]
26+
>
2627
> 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+
>
2930
```caddyfile
3031
localhost
3132
@@ -41,7 +42,7 @@ php_server {
4142

4243
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}`
4344

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:
4546

4647
```caddyfile
4748
localhost
@@ -56,7 +57,7 @@ php_server {
5657
}
5758
```
5859

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:
6061

6162
```caddyfile
6263
localhost
@@ -95,12 +96,22 @@ To use it, add the following to your main layout:
9596
<?php endif ?>
9697
```
9798

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).
100101

101102
Alternatively, you can implement your own client-side logic by subscribing directly to the Mercure hub using the `EventSource` native JavaScript class.
102103

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+
<div data-frankenphp-hot-reload-preserve><!-- My debug bar --></div>
112+
```
113+
114+
## Worker Mode
104115

105116
If you are running your application in [Worker Mode](https://frankenphp.dev/docs/worker/), your application script remains in memory.
106117
This means changes to your PHP code will not be reflected immediately, even if the browser reloads.
@@ -127,7 +138,7 @@ php_server {
127138
}
128139
```
129140

130-
### How it works
141+
## How It Works
131142

132143
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).
133144
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

Comments
 (0)