fix: improve external survey loading (#35811)

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
This commit is contained in:
Lucas Faria
2025-07-29 20:09:00 -03:00
committed by GitHub
parent fa5a00482c
commit ff0910fe10
10 changed files with 68 additions and 73 deletions

View File

@@ -10,7 +10,7 @@
"cypress-axe": "^1.5.0",
"cypress-network-idle": "^1.14.2",
"cypress-terminal-report": "^6.1.0",
"posthog-js": "1.258.2",
"posthog-js": "1.258.3",
"typescript": "5.2.2"
},
"devDependencies": {

View File

@@ -6,7 +6,7 @@
"mobile-replay:schema:build:json": "pnpm mobile-replay:web:schema:build:json && pnpm mobile-replay:mobile:schema:build:json"
},
"dependencies": {
"posthog-js": "1.258.2"
"posthog-js": "1.258.3"
},
"devDependencies": {
"ts-json-schema-generator": "^v2.4.0-next.6"

View File

@@ -183,7 +183,7 @@
"openai": "^4.81.0",
"papaparse": "^5.4.1",
"pmtiles": "^2.11.0",
"posthog-js": "1.258.2",
"posthog-js": "1.258.3",
"posthog-js-lite": "4.1.0",
"prettier": "^2.8.8",
"prop-types": "^15.7.2",

102
pnpm-lock.yaml generated
View File

@@ -384,8 +384,8 @@ importers:
specifier: '*'
version: 4.3.0(postcss@8.5.6)(webpack@5.88.2)
posthog-js:
specifier: 1.258.2
version: 1.258.2(@rrweb/types@2.0.0-alpha.17)
specifier: 1.258.3
version: 1.258.3(@rrweb/types@2.0.0-alpha.17)
sass-loader:
specifier: '*'
version: 10.3.1(sass@1.56.0)(webpack@5.88.2)
@@ -457,8 +457,8 @@ importers:
specifier: '*'
version: 8.57.0
posthog-js:
specifier: 1.258.2
version: 1.258.2(@rrweb/types@2.0.0-alpha.17)
specifier: 1.258.3
version: 1.258.3(@rrweb/types@2.0.0-alpha.17)
prettier:
specifier: '*'
version: 3.4.2
@@ -887,8 +887,8 @@ importers:
specifier: ^2.11.0
version: 2.11.0
posthog-js:
specifier: 1.258.2
version: 1.258.2(@rrweb/types@2.0.0-alpha.17)
specifier: 1.258.3
version: 1.258.3(@rrweb/types@2.0.0-alpha.17)
posthog-js-lite:
specifier: 4.1.0
version: 4.1.0
@@ -1742,8 +1742,8 @@ importers:
specifier: '*'
version: 3.0.1(kea@3.1.5(react@18.2.0))
posthog-js:
specifier: 1.258.2
version: 1.258.2(@rrweb/types@2.0.0-alpha.17)
specifier: 1.258.3
version: 1.258.3(@rrweb/types@2.0.0-alpha.17)
react:
specifier: '*'
version: 18.2.0
@@ -2069,8 +2069,8 @@ importers:
specifier: '*'
version: 3.0.1(kea@3.1.5(react@18.2.0))
posthog-js:
specifier: 1.258.2
version: 1.258.2(@rrweb/types@2.0.0-alpha.17)
specifier: 1.258.3
version: 1.258.3(@rrweb/types@2.0.0-alpha.17)
react:
specifier: '*'
version: 18.2.0
@@ -2264,8 +2264,8 @@ importers:
specifier: '*'
version: 3.2.1(kea@3.1.5(react@18.2.0))
posthog-js:
specifier: 1.258.2
version: 1.258.2(@rrweb/types@2.0.0-alpha.17)
specifier: 1.258.3
version: 1.258.3(@rrweb/types@2.0.0-alpha.17)
react:
specifier: '*'
version: 18.2.0
@@ -14085,8 +14085,8 @@ packages:
posthog-js-lite@4.1.0:
resolution: {integrity: sha512-a+MoPmflhYtnKOuDg7tEgeiwT70mWwcZdqeMhduJw/3LPTFMTvnssTJ0jppmnwTkBoPdBgLYTO40l8k64Tl/yQ==}
posthog-js@1.258.2:
resolution: {integrity: sha512-XBSeiN4HjiYsy3tW5zss8WOJF2JXTQXAYw2wZ+zjqQuzzi7kkLEXjIgsVrBnt5Opwhqn0krZVsb0ZBw34dIiyQ==}
posthog-js@1.258.3:
resolution: {integrity: sha512-bX4Ehzo/yBGY7o23CUAQelX+oUdLn5bKhEjTSiveXsjkZhRURxfKDinYTwI6tjs19FC8BWfHFyO3q3TgT2E7CA==}
peerDependencies:
'@rrweb/types': 2.0.0-alpha.17
rrweb-snapshot: 2.0.0-alpha.17
@@ -16431,8 +16431,8 @@ packages:
resolution: {integrity: sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==}
engines: {node: '>= 10.0.0'}
unlayer-types@1.285.0:
resolution: {integrity: sha512-IiGGiqUOx+Yp1fIyKzzfhIMzt1SfbglnS8+I1O/aY7UyTiMz53HbRsGDM42cgbA7hvzFMjcbZfsy1Hfr5EZv5w==}
unlayer-types@1.287.0:
resolution: {integrity: sha512-uBjqRzO68BLYDlbDIp2sHQMOzuynUYYAbFjARLv6CzEOwno+8rtylYdo6Ew6apo4+74nc2JAACMd4w36pkf6Rg==}
unpipe@1.0.0:
resolution: {integrity: sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==}
@@ -18071,7 +18071,7 @@ snapshots:
'@babel/traverse': 7.28.0
'@babel/types': 7.28.1
convert-source-map: 2.0.0
debug: 4.4.1(supports-color@5.5.0)
debug: 4.4.1(supports-color@8.1.1)
gensync: 1.0.0-beta.2
json5: 2.2.3
semver: 6.3.1
@@ -18181,7 +18181,7 @@ snapshots:
'@babel/core': 7.26.0
'@babel/helper-compilation-targets': 7.25.9
'@babel/helper-plugin-utils': 7.24.7
debug: 4.4.1(supports-color@5.5.0)
debug: 4.4.1(supports-color@8.1.1)
lodash.debounce: 4.0.8
resolve: 1.22.8
transitivePeerDependencies:
@@ -18192,7 +18192,7 @@ snapshots:
'@babel/core': 7.28.0
'@babel/helper-compilation-targets': 7.25.9
'@babel/helper-plugin-utils': 7.24.7
debug: 4.4.1(supports-color@5.5.0)
debug: 4.4.1(supports-color@8.1.1)
lodash.debounce: 4.0.8
resolve: 1.22.8
transitivePeerDependencies:
@@ -18203,7 +18203,7 @@ snapshots:
'@babel/core': 7.26.0
'@babel/helper-compilation-targets': 7.25.9
'@babel/helper-plugin-utils': 7.24.7
debug: 4.4.1(supports-color@5.5.0)
debug: 4.4.1(supports-color@8.1.1)
lodash.debounce: 4.0.8
resolve: 1.22.8
transitivePeerDependencies:
@@ -18214,7 +18214,7 @@ snapshots:
'@babel/core': 7.28.0
'@babel/helper-compilation-targets': 7.25.9
'@babel/helper-plugin-utils': 7.24.7
debug: 4.4.1(supports-color@5.5.0)
debug: 4.4.1(supports-color@8.1.1)
lodash.debounce: 4.0.8
resolve: 1.22.8
transitivePeerDependencies:
@@ -18225,7 +18225,7 @@ snapshots:
'@babel/core': 7.26.0
'@babel/helper-compilation-targets': 7.25.9
'@babel/helper-plugin-utils': 7.24.7
debug: 4.4.1(supports-color@5.5.0)
debug: 4.4.1(supports-color@8.1.1)
lodash.debounce: 4.0.8
resolve: 1.22.8
transitivePeerDependencies:
@@ -18236,7 +18236,7 @@ snapshots:
'@babel/core': 7.28.0
'@babel/helper-compilation-targets': 7.25.9
'@babel/helper-plugin-utils': 7.24.7
debug: 4.4.1(supports-color@5.5.0)
debug: 4.4.1(supports-color@8.1.1)
lodash.debounce: 4.0.8
resolve: 1.22.8
transitivePeerDependencies:
@@ -19675,7 +19675,7 @@ snapshots:
'@babel/parser': 7.28.0
'@babel/template': 7.27.2
'@babel/types': 7.28.1
debug: 4.4.1(supports-color@5.5.0)
debug: 4.4.1(supports-color@8.1.1)
transitivePeerDependencies:
- supports-color
@@ -20232,7 +20232,7 @@ snapshots:
'@eslint/eslintrc@2.1.4':
dependencies:
ajv: 6.12.6
debug: 4.4.1(supports-color@5.5.0)
debug: 4.4.1(supports-color@8.1.1)
espree: 9.6.1
globals: 13.23.0
ignore: 5.2.4
@@ -20362,7 +20362,7 @@ snapshots:
'@humanwhocodes/config-array@0.11.14':
dependencies:
'@humanwhocodes/object-schema': 2.0.3
debug: 4.4.1(supports-color@5.5.0)
debug: 4.4.1(supports-color@8.1.1)
minimatch: 3.1.2
transitivePeerDependencies:
- supports-color
@@ -20779,7 +20779,7 @@ snapshots:
'@open-draft/until': 1.0.3
'@types/debug': 4.1.7
'@xmldom/xmldom': 0.8.6
debug: 4.4.1(supports-color@5.5.0)
debug: 4.4.1(supports-color@8.1.1)
headers-polyfill: 3.2.5
outvariant: 1.4.0
strict-event-emitter: 0.2.8
@@ -24162,7 +24162,7 @@ snapshots:
'@storybook/react-docgen-typescript-plugin@1.0.6--canary.9.0c3f3b7.0(typescript@5.2.2)(webpack@5.88.2)':
dependencies:
debug: 4.4.1(supports-color@5.5.0)
debug: 4.4.1(supports-color@8.1.1)
endent: 2.1.0
find-cache-dir: 3.3.2
flat-cache: 3.2.0
@@ -25590,7 +25590,7 @@ snapshots:
dependencies:
'@typescript-eslint/typescript-estree': 7.1.1(typescript@5.2.2)
'@typescript-eslint/utils': 7.1.1(eslint@8.57.0)(typescript@5.2.2)
debug: 4.4.1(supports-color@5.5.0)
debug: 4.4.1(supports-color@8.1.1)
eslint: 8.57.0
ts-api-utils: 1.0.2(typescript@5.2.2)
optionalDependencies:
@@ -25604,7 +25604,7 @@ snapshots:
dependencies:
'@typescript-eslint/types': 7.1.1
'@typescript-eslint/visitor-keys': 7.1.1
debug: 4.4.1(supports-color@5.5.0)
debug: 4.4.1(supports-color@8.1.1)
globby: 11.1.0
is-glob: 4.0.3
minimatch: 9.0.3
@@ -25842,7 +25842,7 @@ snapshots:
agent-base@6.0.2:
dependencies:
debug: 4.4.1(supports-color@5.5.0)
debug: 4.4.1(supports-color@8.1.1)
transitivePeerDependencies:
- supports-color
@@ -25850,7 +25850,7 @@ snapshots:
agentkeepalive@4.3.0:
dependencies:
debug: 4.4.1(supports-color@5.5.0)
debug: 4.4.1(supports-color@8.1.1)
depd: 2.0.0
humanize-ms: 1.2.1
transitivePeerDependencies:
@@ -27815,7 +27815,7 @@ snapshots:
detect-port@1.5.1:
dependencies:
address: 1.2.2
debug: 4.4.1(supports-color@5.5.0)
debug: 4.4.1(supports-color@8.1.1)
transitivePeerDependencies:
- supports-color
@@ -28193,7 +28193,7 @@ snapshots:
esbuild-register@3.5.0(esbuild@0.18.20):
dependencies:
debug: 4.4.1(supports-color@5.5.0)
debug: 4.4.1(supports-color@8.1.1)
esbuild: 0.18.20
transitivePeerDependencies:
- supports-color
@@ -28767,7 +28767,7 @@ snapshots:
dependencies:
chalk: 4.1.2
commander: 5.1.0
debug: 4.4.1(supports-color@5.5.0)
debug: 4.4.1(supports-color@8.1.1)
transitivePeerDependencies:
- supports-color
@@ -29542,14 +29542,14 @@ snapshots:
dependencies:
'@tootallnate/once': 2.0.0
agent-base: 6.0.2
debug: 4.4.1(supports-color@5.5.0)
debug: 4.4.1(supports-color@8.1.1)
transitivePeerDependencies:
- supports-color
http-proxy-agent@7.0.2:
dependencies:
agent-base: 7.1.4
debug: 4.4.1(supports-color@5.5.0)
debug: 4.4.1(supports-color@8.1.1)
transitivePeerDependencies:
- supports-color
@@ -29562,21 +29562,21 @@ snapshots:
https-proxy-agent@4.0.0:
dependencies:
agent-base: 5.1.1
debug: 4.4.1(supports-color@5.5.0)
debug: 4.4.1(supports-color@8.1.1)
transitivePeerDependencies:
- supports-color
https-proxy-agent@5.0.1:
dependencies:
agent-base: 6.0.2
debug: 4.4.1(supports-color@5.5.0)
debug: 4.4.1(supports-color@8.1.1)
transitivePeerDependencies:
- supports-color
https-proxy-agent@7.0.6:
dependencies:
agent-base: 7.1.4
debug: 4.4.1(supports-color@5.5.0)
debug: 4.4.1(supports-color@8.1.1)
transitivePeerDependencies:
- supports-color
@@ -30053,7 +30053,7 @@ snapshots:
istanbul-lib-source-maps@4.0.1:
dependencies:
debug: 4.4.1(supports-color@5.5.0)
debug: 4.4.1(supports-color@8.1.1)
istanbul-lib-coverage: 3.2.0
source-map: 0.6.1
transitivePeerDependencies:
@@ -30930,7 +30930,7 @@ snapshots:
dependencies:
chalk: 5.4.1
commander: 13.1.0
debug: 4.4.1(supports-color@5.5.0)
debug: 4.4.1(supports-color@8.1.1)
execa: 8.0.1
lilconfig: 3.1.3
listr2: 8.3.3
@@ -31321,7 +31321,7 @@ snapshots:
micromark@2.11.4:
dependencies:
debug: 4.4.1(supports-color@5.5.0)
debug: 4.4.1(supports-color@8.1.1)
parse-entities: 2.0.0
transitivePeerDependencies:
- supports-color
@@ -32946,7 +32946,7 @@ snapshots:
posthog-js-lite@4.1.0: {}
posthog-js@1.258.2(@rrweb/types@2.0.0-alpha.17):
posthog-js@1.258.3(@rrweb/types@2.0.0-alpha.17):
dependencies:
core-js: 3.44.0
fflate: 0.4.8
@@ -33235,7 +33235,7 @@ snapshots:
puppeteer-core@2.1.1:
dependencies:
'@types/mime-types': 2.1.1
debug: 4.4.1(supports-color@5.5.0)
debug: 4.4.1(supports-color@8.1.1)
extract-zip: 1.7.0
https-proxy-agent: 4.0.0
mime: 2.6.0
@@ -33752,7 +33752,7 @@ snapshots:
react-email-editor@1.7.11(react@18.2.0):
dependencies:
react: 18.2.0
unlayer-types: 1.285.0
unlayer-types: 1.287.0
react-error-overlay@6.0.9: {}
@@ -34209,7 +34209,7 @@ snapshots:
retry-request@4.2.2:
dependencies:
debug: 4.4.1(supports-color@5.5.0)
debug: 4.4.1(supports-color@8.1.1)
extend: 3.0.2
transitivePeerDependencies:
- supports-color
@@ -34646,7 +34646,7 @@ snapshots:
socks-proxy-agent@8.0.5:
dependencies:
agent-base: 7.1.4
debug: 4.4.1(supports-color@5.5.0)
debug: 4.4.1(supports-color@8.1.1)
socks: 2.8.3
transitivePeerDependencies:
- supports-color
@@ -35095,7 +35095,7 @@ snapshots:
dependencies:
component-emitter: 1.3.1
cookiejar: 2.1.4
debug: 4.4.1(supports-color@5.5.0)
debug: 4.4.1(supports-color@8.1.1)
fast-safe-stringify: 2.1.1
form-data: 4.0.1
formidable: 3.5.1
@@ -35756,7 +35756,7 @@ snapshots:
universalify@2.0.0: {}
unlayer-types@1.285.0: {}
unlayer-types@1.287.0: {}
unpipe@1.0.0: {}
@@ -35984,7 +35984,7 @@ snapshots:
dependencies:
chalk: 2.4.2
commander: 3.0.2
debug: 4.4.1(supports-color@5.5.0)
debug: 4.4.1(supports-color@8.1.1)
transitivePeerDependencies:
- supports-color

View File

@@ -4,7 +4,7 @@ from datetime import datetime, timedelta, UTC
import re
from typing import Any, cast, TypedDict
from urllib.parse import urlparse
import json
import orjson
import nh3
import posthoganalytics
@@ -1397,11 +1397,7 @@ def public_survey_page(request, survey_id: str):
# Database query with minimal fields and timeout protection
try:
survey = (
Survey.objects.select_related("team")
.only("id", "name", "appearance", "archived", "type", "team__id", "team__api_token")
.get(id=survey_id)
)
survey = Survey.objects.select_related("team").get(id=survey_id)
except Survey.DoesNotExist:
logger.info("survey_page_not_found", survey_id=survey_id)
# Use generic error message to prevent survey ID enumeration
@@ -1458,11 +1454,12 @@ def public_survey_page(request, survey_id: str):
if hasattr(survey.team, "ui_host") and survey.team.ui_host:
project_config["ui_host"] = survey.team.ui_host
serializer = SurveyAPISerializer(survey)
survey_data = serializer.data
context = {
"name": survey.name,
"id": survey.id,
"appearance": json.dumps(survey.appearance),
"project_config_json": json.dumps(project_config),
"survey_data": orjson.dumps(survey_data).decode("utf-8"),
"project_config_json": orjson.dumps(project_config).decode("utf-8"),
"debug": settings.DEBUG,
}

View File

@@ -150,7 +150,7 @@ class TestExternalSurveys(APIBaseTest):
# Check appearance data is injected
content = response.content.decode()
assert "surveyAppearance" in content
assert "survey.appearance" in content
assert "#ff0000" in content
assert "#00ff00" in content

View File

@@ -590,10 +590,8 @@
<!-- PostHog JavaScript -->
<script>
// Project config from Django and helper functions
const survey = {{ survey_data | safe }};
const projectConfig = {{ project_config_json | safe }};
const surveyName = "{{ name }}";
const surveyId = "{{ id }}";
const surveyAppearance = {{ appearance | safe }};
const BLACK_TEXT_COLOR = '#020617'
@@ -883,8 +881,8 @@
}
// Apply survey appearance if available
if (surveyAppearance) {
applySurveyAppearance(surveyAppearance);
if (survey.appearance) {
applySurveyAppearance(survey.appearance);
}
</script>
<script>
@@ -930,7 +928,7 @@
posthog.init(projectConfig.token, config);
posthog.onSurveysLoaded(() => {
posthog.surveys["_renderExternalSurvey"](surveyId, '#posthog-survey-container');
posthog.surveys["_surveyManager"].renderSurvey(survey, document.getElementById('posthog-survey-container'));
});
</script>
</body>

View File

@@ -2,7 +2,7 @@
"name": "@posthog/products-error-tracking",
"scripts": {},
"dependencies": {
"posthog-js": "1.258.2"
"posthog-js": "1.258.3"
},
"peerDependencies": {
"@dnd-kit/core": "*",

View File

@@ -1,7 +1,7 @@
{
"name": "@posthog/products-messaging",
"dependencies": {
"posthog-js": "1.258.2"
"posthog-js": "1.258.3"
},
"peerDependencies": {
"@posthog/icons": "*",

View File

@@ -1,7 +1,7 @@
{
"name": "@posthog/products-user-interviews",
"dependencies": {
"posthog-js": "1.258.2"
"posthog-js": "1.258.3"
},
"peerDependencies": {
"@posthog/icons": "*",