Title: Angular Service Worker breaks HTML forms POST submit · Issue #36368 · angular/angular · GitHub
Open Graph Title: Angular Service Worker breaks HTML forms POST submit · Issue #36368 · angular/angular
X Title: Angular Service Worker breaks HTML forms POST submit · Issue #36368 · angular/angular
Description: 🐞 bug report Affected Package The issue is caused by package @angular/service-worker Is this a regression? No Description We have an hybrid stack with old school PHP pages mixed with an Angular SPA, and the Angular app has a wildcard rou...
Open Graph Description: 🐞 bug report Affected Package The issue is caused by package @angular/service-worker Is this a regression? No Description We have an hybrid stack with old school PHP pages mixed with an Angular SPA...
X Description: 🐞 bug report Affected Package The issue is caused by package @angular/service-worker Is this a regression? No Description We have an hybrid stack with old school PHP pages mixed with an Angular SPA...
Opengraph URL: https://github.com/angular/angular/issues/36368
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Angular Service Worker breaks HTML forms POST submit","articleBody":"\u003c!--🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅\r\n\r\nOh hi there! 😄\r\n\r\nTo expedite issue processing please search open and closed issues before submitting a new one.\r\nExisting issues often contain information about workarounds, resolution, or progress updates.\r\n\r\n🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅-->\r\n\r\n\r\n# 🐞 bug report\r\n\r\n### Affected Package\r\n\u003c!-- Can you pin-point one or more @angular/* packages as the source of the bug? -->\r\nThe issue is caused by package @angular/service-worker\r\n\r\n\r\n### Is this a regression?\r\n\r\n\u003c!-- Did this behavior use to work in the previous version? -->\r\nNo\r\n\r\n### Description\r\n\r\nWe have an hybrid stack with old school PHP pages mixed with an Angular SPA, and the Angular app has a wildcard route redirecting all non-SPA navigations to the legacy PHP stack.\r\n\r\nCombined with using the `ngsw-bypass` query param, the Angular Service Worker works great in most situations. However, it does break HTML forms `POST` submit, as the Service Worker would then return the app shell (even though `req.method` was `post`), causing the SPA to send a new `GET` request with the `ngsw-bypass` query param, and breaking the form submission.\r\n\r\nTo be clear, the entire reason why this is an issue for us is that we have way too many unknown PHP `POST` endpoints to be able to exclude them all from the `navigationUrls` regexes (and they often live next to actual SPA routes); the issue does not exist if the `POST` endpoint is excluded from `navigationUrls`.\r\n\r\nPatching `ngsw-worker.js` at build time solves our issue, however, considering that POST requests aren't supported by the Cache API / can't really be cached by Service Workers, that upload progress events are broken as well, and that (in our case) HTML form POST submits are broken when form action targets match `navigationUrls`, I wonder it there's a point for the Angular Service Worker to handle `POST` requests in the first place.\r\n\r\ni.e., is there any downside for the Angular Service Worker to not handle any `POST` requests at all like we've done?\r\n\r\n```\r\nif (req.method === 'POST' || req.headers.has('ngsw-bypass') || /[?&]ngsw-bypass(?:[=&]|$)/i.test(requestUrlObj.search)) {\r\n return;\r\n}\r\n```\r\n\r\nLooking through the various GitHub issues for related bugs, I feel that this would make real-life Service Worker deployments much easier.\r\n\r\nAlternatively, I would argue that the Angular Service Worker should not return the app shell for `req.mode === 'navigation'` requests if `req.method` is not `GET`, in order to stay on the safe side.\r\n\r\n## 🔬 Minimal Reproduction\r\n\u003c!--\r\nPlease create and share minimal reproduction of the issue starting with this template: https://stackblitz.com/fork/angular-issue-repro2\r\n-->\r\nI've created a small repro at https://github.com/laurentgoudet/angular-service-worker-submit-post-bug: just `git checkout`, `yarn`, `node server.js`, and open `http://localhost:8080`: the form submit would be broken once the Service Worker has bootstrapped\r\n\r\n## 🌍 Your Environment\r\n\r\n**Angular Version:**\r\n\u003cpre>\u003ccode>\r\nlaurent@Laurents-MacBook-Pro webapp [laurent-sw-fix] $ ./node_modules/.bin/ng version\r\n\r\n _ _ ____ _ ___\r\n / \\ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|\r\n / △ \\ | '_ \\ / _` | | | | |/ _` | '__| | | | | | |\r\n / ___ \\| | | | (_| | |_| | | (_| | | | |___| |___ | |\r\n /_/ \\_\\_| |_|\\__, |\\__,_|_|\\__,_|_| \\____|_____|___|\r\n |___/\r\n\r\n\r\nAngular CLI: 9.0.5\r\nNode: 12.4.0\r\nOS: darwin x64\r\n\r\nAngular: 9.0.5\r\n... animations, cli, common, compiler, compiler-cli, core, forms\r\n... language-service, localize, platform-browser\r\n... platform-browser-dynamic, platform-server, router\r\n... service-worker\r\nIvy Workspace: Yes\r\n\r\nPackage Version\r\n-----------------------------------------------------------\r\n@angular-devkit/architect 0.900.3\r\n@angular-devkit/build-angular 0.900.3\r\n@angular-devkit/build-optimizer 0.900.3\r\n@angular-devkit/build-webpack 0.900.3\r\n@angular-devkit/core 9.0.3\r\n@angular-devkit/schematics 9.0.5\r\n@angular/cdk 9.1.1\r\n@angular/material 9.1.1\r\n@ngtools/webpack 9.0.3\r\n@nguniversal/builders 9.0.1\r\n@nguniversal/common 9.0.2\r\n@nguniversal/express-engine 9.0.2\r\n@schematics/angular 9.0.5\r\n@schematics/update 0.900.5\r\nrxjs 6.5.4\r\ntypescript 3.7.5\r\nwebpack 4.41.2\r\n\r\n\u003c/code>\u003c/pre>","author":{"url":"https://github.com/laurentgoudet","@type":"Person","name":"laurentgoudet"},"datePublished":"2020-04-01T12:46:27Z","url":"https://github.com/angular/angular/issues/36368"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:74f6395e-991f-411d-f2a7-d70bdf39ce54 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9CB8:215B92:12436D1:1853C69:6B0121A0 |
| html-safe-nonce | 26d80fffc5eeef61aba2b3826e0a73d92014f479fd7526de7b5dc07950d9f2bb |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5Q0I4OjIxNUI5MjoxMjQzNkQxOjE4NTNDNjk6NkIwMTIxQTAiLCJ2aXNpdG9yX2lkIjoiNTMyNTQ1NjgzNDAyOTQ5NDY4OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 354275942b2229237ef707750f5a6dab7344676881306c30b0c81184eddb3bba |
| hovercard-subject-tag | issue:591888747 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular/36368/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5635eeac922541b8db2abad85eb53ad2121e9983a7993585342e6d1f383256fb/angular/angular/issues/36368 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5635eeac922541b8db2abad85eb53ad2121e9983a7993585342e6d1f383256fb/angular/angular/issues/36368 |
| og:image:alt | 🐞 bug report Affected Package The issue is caused by package @angular/service-worker Is this a regression? No Description We have an hybrid stack with old school PHP pages mixed with an Angular SPA... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | laurentgoudet |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular git https://github.com/angular/angular.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 24195339 |
| octolytics-dimension-repository_nwo | angular/angular |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24195339 |
| octolytics-dimension-repository_network_root_nwo | angular/angular |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width